Ignore:
Timestamp:
Mar 16, 2014, 10:35:53 AM (11 years ago)
Author:
Darin Adler
Message:

Remove all uses of deprecatedCharacters from JavaScriptCore
https://bugs.webkit.org/show_bug.cgi?id=130304

Reviewed by Anders Carlsson.

Source/JavaScriptCore:

  • API/JSValueRef.cpp:

(JSValueMakeFromJSONString): Use characters16 in the 16-bit code path.

  • API/OpaqueJSString.cpp:

(OpaqueJSString::~OpaqueJSString): Use characters 16 in the 16-bit code path.
(OpaqueJSString::identifier): Get rid of custom Identifier constructor, and
juse use the standard one that takes a String.
(OpaqueJSString::characters): Use getCharactersWithUpconvert instead of a
hand-written alternative.

  • bindings/ScriptValue.cpp:

(Deprecated::jsToInspectorValue): Create InspectorString from String directly
instead of involving a character pointer. Use the String from Identifier
directly instead of making a new String.

  • inspector/ContentSearchUtilities.cpp:

(Inspector::ContentSearchUtilities::createSearchRegexSource): Use StringBuilder
instead of building a String a character at a time. This is still a very slow
way to do this. Also use strchr to search for a character instead of building
a String every time just to use find on it.

  • inspector/InspectorValues.cpp:

(Inspector::doubleQuoteString): Remove unnecessary trip through a
character pointer. This is still a really slow way to do this.
(Inspector::InspectorValue::parseJSON): Use StringView::upconvertedCharacters
instead of String::deprecatedCharacters. Still slow to always upconvert.

  • runtime/DateConstructor.cpp: Removed unneeded include.
  • runtime/DatePrototype.cpp: Ditto.
  • runtime/Identifier.h: Removed deprecatedCharacters function.
  • runtime/JSGlobalObjectFunctions.cpp:

(JSC::encode): Added a type cast to avoid ambiguity with the two character-
appending functions from JSStringBuilder. Removed unneeded code duplicating
what JSStringBuilder already does in its character append function.
(JSC::decode): Deleted code that creates a JSStringBuilder that is never used.
(JSC::parseIntOverflow): Changed lengths to unsigned. Made only the overload that
is used outside this file have external linkage. Added a new overload that takes
a StringView.
(JSC::parseInt): Use StringView::substring to call parseIntOverflow.
(JSC::globalFuncEscape): Use JSBuilder::append in a more efficient way for a
single character.

  • runtime/JSGlobalObjectFunctions.h: Removed unused overloads of parseIntOverflow.
  • runtime/JSStringBuilder.h: Marked this "lightly deprecated".

(JSC::JSStringBuilder::append): Overloaded for better speed with 8-bit characters.
Made one overload private. Fixed a performance bug where we would reserve capacity
in the 8-bit buffer but then append to the 16-bit buffer.

  • runtime/ObjectPrototype.cpp: Removed unneeded include.
  • runtime/StringPrototype.cpp:

(JSC::stringProtoFuncFontsize): Use StringView::getCharactersWithUpconvert.
(JSC::stringProtoFuncLink): Ditto.

Source/WTF:

  • wtf/dtoa.h:

(WTF::parseDouble): Added an overload that takes a StringView.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSStringBuilder.h

    r162784 r165703  
    3333namespace JSC {
    3434
     35// FIXME: Should move the last few callers over from this to WTF::StringBuilder.
    3536class JSStringBuilder {
    3637public:
     
    4142    }
    4243
    43     void append(const UChar u)
     44    void append(LChar character)
    4445    {
    4546        if (m_is8Bit) {
    46             if (u < 0xff) {
    47                 LChar c = u;
    48                 m_okay &= buffer8.tryAppend(&c, 1);
     47            m_okay &= buffer8.tryAppend(&character, 1);
     48            return;
     49        }
     50        UChar upconvertedCharacter = character;
     51        m_okay &= buffer16.tryAppend(&upconvertedCharacter, 1);
     52    }
     53
     54    void append(UChar character)
     55    {
     56        if (m_is8Bit) {
     57            if (character < 0x100) {
     58                LChar narrowedCharacter = character;
     59                m_okay &= buffer8.tryAppend(&narrowedCharacter, 1);
    4960                return;
    5061            }
    5162            upConvert();
    5263        }
    53         m_okay &= buffer16.tryAppend(&u, 1);
     64        m_okay &= buffer16.tryAppend(&character, 1);
    5465    }
    5566
    5667    void append(const char* str)
    5768    {
    58         append(str, strlen(str));
    59     }
    60 
    61     void append(const char* str, size_t len)
    62     {
    63         if (m_is8Bit) {
    64             m_okay &= buffer8.tryAppend(reinterpret_cast<const LChar*>(str), len);
    65             return;
    66         }
    67         m_okay &= buffer8.tryReserveCapacity(buffer16.size() + len);
    68         for (size_t i = 0; i < len; i++) {
    69             UChar u = static_cast<unsigned char>(str[i]);
    70             m_okay &= buffer16.tryAppend(&u, 1);
    71         }
    72     }
    73 
    74     void append(const LChar* str, size_t len)
    75     {
    76         if (m_is8Bit) {
    77             m_okay &= buffer8.tryAppend(str, len);
    78             return;
    79         }
    80         m_okay &= buffer8.tryReserveCapacity(buffer16.size() + len);
    81         for (size_t i = 0; i < len; i++) {
    82             UChar u = str[i];
    83             m_okay &= buffer16.tryAppend(&u, 1);
    84         }
    85     }
    86    
    87     void append(const UChar* str, size_t len)
    88     {
    89         if (m_is8Bit)
    90             upConvert(); // FIXME: We could check character by character its size.
    91         m_okay &= buffer16.tryAppend(str, len);
    92     }
    93 
    94     void append(const String& str)
    95     {
    96         unsigned length = str.length();
    97 
    98         if (!length)
    99             return;
    100 
    101         if (m_is8Bit) {
    102             if (str.is8Bit()) {
    103                 m_okay &= buffer8.tryAppend(str.characters8(), length);
    104                 return;
    105             }
    106             upConvert();
    107         }
    108         m_okay &= buffer16.tryAppend(str.deprecatedCharacters(), length);
    109     }
    110 
    111     void upConvert()
    112     {
    113         ASSERT(m_is8Bit);
    114         size_t len = buffer8.size();
    115 
    116         for (size_t i = 0; i < len; i++)
    117             buffer16.append(buffer8[i]);
    118 
    119         buffer8.clear();
    120         m_is8Bit = false;
     69        append(reinterpret_cast<const LChar*>(str), strlen(str));
    12170    }
    12271
     
    13786    }
    13887
    139 protected:
     88private:
     89    void append(const LChar* characters, size_t length)
     90    {
     91        if (m_is8Bit) {
     92            m_okay &= buffer8.tryAppend(characters, length);
     93            return;
     94        }
     95        // FIXME: There must be a more efficient way of doing this.
     96        m_okay &= buffer16.tryReserveCapacity(buffer16.size() + length);
     97        for (size_t i = 0; i < length; i++) {
     98            UChar upconvertedCharacter = characters[i];
     99            m_okay &= buffer16.tryAppend(&upconvertedCharacter, 1);
     100        }
     101    }
     102
     103    void upConvert()
     104    {
     105        ASSERT(m_is8Bit);
     106        size_t len = buffer8.size();
     107
     108        for (size_t i = 0; i < len; i++)
     109            buffer16.append(buffer8[i]);
     110
     111        buffer8.clear();
     112        m_is8Bit = false;
     113    }
     114
    140115    Vector<LChar, 64, UnsafeVectorOverflow> buffer8;
    141116    Vector<UChar, 64, UnsafeVectorOverflow> buffer16;
Note: See TracChangeset for help on using the changeset viewer.