Changeset 161840 in webkit


Ignore:
Timestamp:
Jan 12, 2014 3:23:44 PM (10 years ago)
Author:
Darin Adler
Message:

Reduce use of String::characters
https://bugs.webkit.org/show_bug.cgi?id=126854

Reviewed by Sam Weinig.

Source/JavaScriptCore:

  • API/JSValueRef.cpp:

(JSValueMakeFromJSONString): Use characters16 instead of characters for 16-bit case.
Had to remove length check because an empty string could be either 8 bit or 16 bit.
Don't need a null string check before calling is8Bit because JSStringRef can't hold
a null string.

  • bindings/ScriptValue.cpp:

(Deprecated::jsToInspectorValue): Use the existing string here instead of creating
a new one by calling characters and length on the old string. I think this may be
left over from when string types were not the same in JavaScriptCore and WebCore.
Also rewrite the property names loop to use modern for syntax and fewer locals.

  • inspector/InspectorValues.cpp:

(Inspector::escapeChar): Changed to use appendLiteral instead of hard-coding string
lengths. Moved handling of "<" and ">" in here instead of at the call site.
(Inspector::doubleQuoteString): Simplify the code so there is no use of characters
and length. This is still an inefficient way of doing this job and could use a rethink.

  • runtime/DatePrototype.cpp:

(JSC::formatLocaleDate): Use RetainPtr, createCFString, and the conversion from
CFStringRef to WTF::String to remove a lot of unneeded code.

  • runtime/Identifier.h: Removed unneeded Identifier::characters function.
  • runtime/JSStringBuilder.h:

(JSC::JSStringBuilder::append): Use characters16 instead of characters function here,
since we have already checked is8Bit above.

Source/WebCore:

  • bindings/objc/WebScriptObject.mm:

(+[WebScriptObject _convertValueToObjcValue:JSC::originRootObject:rootObject:]):
Get rid of unneeded code to turn a WTF::String into an NSString, since that's
built into the WTF::String class.

  • editing/CompositeEditCommand.cpp:

(WebCore::containsOnlyWhitespace): Use WTF::String's [] operator instead of
an explicit call to the characters function. Small performance cost.

  • editing/TypingCommand.cpp:

(WebCore::TypingCommand::insertText): Ditto.

  • editing/VisibleUnits.cpp:

(WebCore::startOfParagraph): Use reverseFind instead of writing our own loop.
(WebCore::endOfParagraph): Use find instead of writing our own loop.

  • html/parser/HTMLParserIdioms.cpp:

(WebCore::stripLeadingAndTrailingHTMLSpaces): Use characters16 instead of
characters since we have already checked is8Bit.
(WebCore::parseHTMLNonNegativeInteger): Ditto. Replace the length check with
a check of isNull since a zero length string could be 8 bit, but it's not
safe to call is8Bit on a null WTF::String. (That should probably be fixed.)

  • inspector/ContentSearchUtils.cpp:

(WebCore::ContentSearchUtils::createSearchRegexSource): Use StringBuilder
instead of String in code that builds up a string one character at a time.
The old way was ridiculously slow because it allocated a new string for every
character; the new way still isn't all that efficient, but it's better. Also
changed to use strchr instead of WTF::String::find for special characters.

  • inspector/InspectorStyleSheet.cpp:

(WebCore::InspectorStyle::newLineAndWhitespaceDelimiters): Use WTF::String's
[] operator instead of an explicit call to the characters function.

  • inspector/InspectorStyleTextEditor.cpp:

(WebCore::InspectorStyleTextEditor::insertProperty): Ditto.
(WebCore::InspectorStyleTextEditor::internalReplaceProperty): Ditto.

  • platform/Length.cpp:

(WebCore::newCoordsArray): Ditto.

  • platform/LinkHash.cpp:

(WebCore::visitedLinkHash): Use characters16 instead of characters since
we have already checked is8Bit. Replace the length check with a check of
isNull (as above in parseHTMLNonNegativeInteger).

  • platform/graphics/Color.cpp:

(WebCore::Color::parseHexColor): Use characters16 since we already checked is8Bit.
(WebCore::Color::Color): Ditto.

  • platform/graphics/TextRun.h:

(WebCore::TextRun::TextRun): Use characters16 instead of characters since
we have already checked is8Bit. Replace the length check with a check of
isNull (as above in parseHTMLNonNegativeInteger).

  • platform/text/TextEncodingRegistry.cpp:

(WebCore::atomicCanonicalTextEncodingName): Use characters16 instead of
characters since we already checked is8Bit. Also use isEmpty instead of !length.

  • rendering/RenderBlock.cpp:

(WebCore::RenderBlock::constructTextRun): Use characters16 instead of characters
since we have already checked is8Bit. Replace the length check with a check of
isNull (as above in parseHTMLNonNegativeInteger).

  • rendering/RenderCombineText.cpp:

(WebCore::RenderCombineText::width): Check for zero length instead of checking
for null characters.

  • svg/SVGFontElement.cpp:

(WebCore::SVGFontElement::registerLigaturesInGlyphCache): Rewrite ligatures
for loop and give local variables a better name. Construct the substring with
the substring function. Still a really inefficient approach -- allocating a new
string for every character is absurdly expensive.

  • xml/XPathFunctions.cpp:

(WebCore::XPath::FunId::evaluate): Use String instead of StringBuilder. Still
not all that efficient, but better than before. Use substring to construct the
substring.

  • xml/XPathNodeSet.h: Added begin and end functions so we can use a C++11 for

loop with this class.

Source/WTF:

  • wtf/text/StringImpl.cpp:

(WTF::StringImpl::replace): Use characters16 here since is8Bit was already checked.

  • wtf/text/WTFString.h:

(WTF::String::isAllSpecialCharacters): Use characters16 here since is8Bit was
already checked. Also renamed "len" to "length".

Location:
trunk/Source
Files:
29 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSValueRef.cpp

    r157688 r161840  
    324324    String str = string->string();
    325325    unsigned length = str.length();
    326     if (length && str.is8Bit()) {
     326    if (str.is8Bit()) {
    327327        LiteralParser<LChar> parser(exec, str.characters8(), length, StrictJSON);
    328328        return toRef(exec, parser.tryLiteralParse());
    329329    }
    330     LiteralParser<UChar> parser(exec, str.characters(), length, StrictJSON);
     330    LiteralParser<UChar> parser(exec, str.characters16(), length, StrictJSON);
    331331    return toRef(exec, parser.tryLiteralParse());
    332332}
  • trunk/Source/JavaScriptCore/ChangeLog

    r161820 r161840  
     12014-01-12  Darin Adler  <darin@apple.com>
     2
     3        Reduce use of String::characters
     4        https://bugs.webkit.org/show_bug.cgi?id=126854
     5
     6        Reviewed by Sam Weinig.
     7
     8        * API/JSValueRef.cpp:
     9        (JSValueMakeFromJSONString): Use characters16 instead of characters for 16-bit case.
     10        Had to remove length check because an empty string could be either 8 bit or 16 bit.
     11        Don't need a null string check before calling is8Bit because JSStringRef can't hold
     12        a null string.
     13
     14        * bindings/ScriptValue.cpp:
     15        (Deprecated::jsToInspectorValue): Use the existing string here instead of creating
     16        a new one by calling characters and length on the old string. I think this may be
     17        left over from when string types were not the same in JavaScriptCore and WebCore.
     18        Also rewrite the property names loop to use modern for syntax and fewer locals.
     19
     20        * inspector/InspectorValues.cpp:
     21        (Inspector::escapeChar): Changed to use appendLiteral instead of hard-coding string
     22        lengths. Moved handling of "<" and ">" in here instead of at the call site.
     23        (Inspector::doubleQuoteString): Simplify the code so there is no use of characters
     24        and length. This is still an inefficient way of doing this job and could use a rethink.
     25
     26        * runtime/DatePrototype.cpp:
     27        (JSC::formatLocaleDate): Use RetainPtr, createCFString, and the conversion from
     28        CFStringRef to WTF::String to remove a lot of unneeded code.
     29
     30        * runtime/Identifier.h: Removed unneeded Identifier::characters function.
     31
     32        * runtime/JSStringBuilder.h:
     33        (JSC::JSStringBuilder::append): Use characters16 instead of characters function here,
     34        since we have already checked is8Bit above.
     35
    1362014-01-12  Andy Estes  <aestes@apple.com>
    237
  • trunk/Source/JavaScriptCore/bindings/ScriptValue.cpp

    r160457 r161840  
    116116    if (value.isNumber())
    117117        return InspectorBasicValue::create(value.asNumber());
    118     if (value.isString()) {
    119         String s = value.getString(scriptState);
    120         return InspectorString::create(String(s.characters(), s.length()));
    121     }
     118    if (value.isString())
     119        return InspectorString::create(value.getString(scriptState));
    122120
    123121    if (value.isObject()) {
     
    139137        PropertyNameArray propertyNames(scriptState);
    140138        object->methodTable()->getOwnPropertyNames(object, scriptState, propertyNames, ExcludeDontEnumProperties);
    141         for (size_t i = 0; i < propertyNames.size(); i++) {
    142             const Identifier& name =  propertyNames[i];
    143             JSValue propertyValue = object->get(scriptState, name);
    144             RefPtr<InspectorValue> inspectorValue = jsToInspectorValue(scriptState, propertyValue, maxDepth);
     139        for (auto& name : propertyNames) {
     140            RefPtr<InspectorValue> inspectorValue = jsToInspectorValue(scriptState, object->get(scriptState, name), maxDepth);
    145141            if (!inspectorValue)
    146142                return nullptr;
    147             inspectorObject->setValue(String(name.characters(), name.length()), inspectorValue);
     143            inspectorObject->setValue(name.string(), inspectorValue);
    148144        }
    149145        return inspectorObject;
  • trunk/Source/JavaScriptCore/inspector/InspectorValues.cpp

    r160457 r161840  
    447447inline bool escapeChar(UChar c, StringBuilder* dst)
    448448{
     449    // Must escape < and > to prevent script execution.
    449450    switch (c) {
    450     case '\b': dst->append("\\b", 2); break;
    451     case '\f': dst->append("\\f", 2); break;
    452     case '\n': dst->append("\\n", 2); break;
    453     case '\r': dst->append("\\r", 2); break;
    454     case '\t': dst->append("\\t", 2); break;
    455     case '\\': dst->append("\\\\", 2); break;
    456     case '"': dst->append("\\\"", 2); break;
     451    case '\b': dst->appendLiteral("\\b"); break;
     452    case '\f': dst->appendLiteral("\\f"); break;
     453    case '\n': dst->appendLiteral("\\n"); break;
     454    case '\r': dst->appendLiteral("\\r"); break;
     455    case '\t': dst->appendLiteral("\\t"); break;
     456    case '\\': dst->appendLiteral("\\\\"); break;
     457    case '"': dst->appendLiteral("\\\""); break;
     458    case '<': dst->appendLiteral("\\u003C"); break;
     459    case '>': dst->appendLiteral("\\u003E"); break;
    457460    default:
    458461        return false;
     
    467470        UChar c = str[i];
    468471        if (!escapeChar(c, dst)) {
    469             if (c < 32 || c > 126 || c == '<' || c == '>') {
    470                 // 1. Escaping <, > to prevent script execution.
    471                 // 2. Technically, we could also pass through c > 126 as UTF8, but this
    472                 //    is also optional.  It would also be a pain to implement here.
    473                 unsigned int symbol = static_cast<unsigned int>(c);
    474                 String symbolCode = String::format("\\u%04X", symbol);
    475                 dst->append(symbolCode.characters(), symbolCode.length());
    476             } else
     472            // We could format c > 126 as UTF-8 instead of escaping them.
     473            if (c >= 32 || c <= 126)
    477474                dst->append(c);
     475            else {
     476                // FIXME: Way too slow to do this by creating and destroying a string each time.
     477                dst->append(String::format("\\u%04X", static_cast<unsigned>(c)));
     478            }
    478479        }
    479480    }
  • trunk/Source/JavaScriptCore/runtime/DatePrototype.cpp

    r156620 r161840  
    163163        timeStyle = styleFromArgString(arg0String, timeStyle);
    164164
    165     CFLocaleRef locale = CFLocaleCopyCurrent();
    166     CFDateFormatterRef formatter = CFDateFormatterCreate(0, locale, dateStyle, timeStyle);
    167     CFRelease(locale);
    168 
    169     if (useCustomFormat) {
    170         CFStringRef customFormatCFString = CFStringCreateWithCharacters(0, customFormatString.characters(), customFormatString.length());
    171         CFDateFormatterSetFormat(formatter, customFormatCFString);
    172         CFRelease(customFormatCFString);
    173     }
    174 
    175     CFStringRef string = CFDateFormatterCreateStringWithAbsoluteTime(0, formatter, floor(timeInMilliseconds / msPerSecond) - kCFAbsoluteTimeIntervalSince1970);
    176 
    177     CFRelease(formatter);
    178 
    179     // We truncate the string returned from CFDateFormatter if it's absurdly long (> 200 characters).
    180     // That's not great error handling, but it just won't happen so it doesn't matter.
    181     UChar buffer[200];
    182     const size_t bufferLength = WTF_ARRAY_LENGTH(buffer);
    183     size_t length = CFStringGetLength(string);
    184     ASSERT(length <= bufferLength);
    185     if (length > bufferLength)
    186         length = bufferLength;
    187     CFStringGetCharacters(string, CFRangeMake(0, length), buffer);
    188 
    189     CFRelease(string);
    190 
    191     return jsNontrivialString(exec, String(buffer, length));
     165    RetainPtr<CFDateFormatterRef> formatter = adoptCF(CFDateFormatterCreate(kCFAllocatorDefault, adoptCF(CFLocaleCopyCurrent()).get(), dateStyle, timeStyle));
     166
     167    if (useCustomFormat)
     168        CFDateFormatterSetFormat(formatter.get(), customFormatString.createCFString().get());
     169
     170    RetainPtr<CFStringRef> string = adoptCF(CFDateFormatterCreateStringWithAbsoluteTime(kCFAllocatorDefault, formatter.get(), floor(timeInMilliseconds / msPerSecond) - kCFAbsoluteTimeIntervalSince1970));
     171
     172    return jsNontrivialString(exec, string.get());
    192173}
    193174
  • trunk/Source/JavaScriptCore/runtime/Identifier.h

    r158498 r161840  
    5656        StringImpl* impl() const { return m_string.impl(); }
    5757       
    58         const UChar* characters() const { return m_string.characters(); }
    5958        int length() const { return m_string.length(); }
    6059       
  • trunk/Source/JavaScriptCore/runtime/JSStringBuilder.h

    r147892 r161840  
    106106            upConvert();
    107107        }
    108         m_okay &= buffer16.tryAppend(str.characters(), length);
     108        m_okay &= buffer16.tryAppend(str.characters16(), length);
    109109    }
    110110
  • trunk/Source/WTF/ChangeLog

    r161818 r161840  
     12014-01-12  Darin Adler  <darin@apple.com>
     2
     3        Reduce use of String::characters
     4        https://bugs.webkit.org/show_bug.cgi?id=126854
     5
     6        Reviewed by Sam Weinig.
     7
     8        * wtf/text/StringImpl.cpp:
     9        (WTF::StringImpl::replace): Use characters16 here since is8Bit was already checked.
     10        * wtf/text/WTFString.h:
     11        (WTF::String::isAllSpecialCharacters): Use characters16 here since is8Bit was
     12        already checked. Also renamed "len" to "length".
     13
    1142014-01-12  Anders Carlsson  <andersca@apple.com>
    215
  • trunk/Source/WTF/wtf/text/StringImpl.cpp

    r161362 r161840  
    14901490            data[i + position + lengthToInsert] = m_data8[i + position + lengthToReplace];
    14911491    } else {
    1492         memcpy(data + position + lengthToInsert, characters() + position + lengthToReplace,
     1492        memcpy(data + position + lengthToInsert, characters16() + position + lengthToReplace,
    14931493            (length() - position - lengthToReplace) * sizeof(UChar));
    14941494    }
  • trunk/Source/WTF/wtf/text/WTFString.h

    r161601 r161840  
    625625inline bool String::isAllSpecialCharacters() const
    626626{
    627     size_t len = length();
    628 
    629     if (!len)
     627    size_t length = this->length();
     628
     629    if (!length)
    630630        return true;
    631631
    632632    if (is8Bit())
    633         return WTF::isAllSpecialCharacters<isSpecialCharacter, LChar>(characters8(), len);
    634     return WTF::isAllSpecialCharacters<isSpecialCharacter, UChar>(characters(), len);
     633        return WTF::isAllSpecialCharacters<isSpecialCharacter>(characters8(), length);
     634    return WTF::isAllSpecialCharacters<isSpecialCharacter>(characters16(), length);
    635635}
    636636
  • trunk/Source/WebCore/ChangeLog

    r161839 r161840  
     12014-01-12  Darin Adler  <darin@apple.com>
     2
     3        Reduce use of String::characters
     4        https://bugs.webkit.org/show_bug.cgi?id=126854
     5
     6        Reviewed by Sam Weinig.
     7
     8        * bindings/objc/WebScriptObject.mm:
     9        (+[WebScriptObject _convertValueToObjcValue:JSC::originRootObject:rootObject:]):
     10        Get rid of unneeded code to turn a WTF::String into an NSString, since that's
     11        built into the WTF::String class.
     12
     13        * editing/CompositeEditCommand.cpp:
     14        (WebCore::containsOnlyWhitespace): Use WTF::String's [] operator instead of
     15        an explicit call to the characters function. Small performance cost.
     16        * editing/TypingCommand.cpp:
     17        (WebCore::TypingCommand::insertText): Ditto.
     18
     19        * editing/VisibleUnits.cpp:
     20        (WebCore::startOfParagraph): Use reverseFind instead of writing our own loop.
     21        (WebCore::endOfParagraph): Use find instead of writing our own loop.
     22
     23        * html/parser/HTMLParserIdioms.cpp:
     24        (WebCore::stripLeadingAndTrailingHTMLSpaces): Use characters16 instead of
     25        characters since we have already checked is8Bit.
     26        (WebCore::parseHTMLNonNegativeInteger): Ditto. Replace the length check with
     27        a check of isNull since a zero length string could be 8 bit, but it's not
     28        safe to call is8Bit on a null WTF::String. (That should probably be fixed.)
     29
     30        * inspector/ContentSearchUtils.cpp:
     31        (WebCore::ContentSearchUtils::createSearchRegexSource): Use StringBuilder
     32        instead of String in code that builds up a string one character at a time.
     33        The old way was ridiculously slow because it allocated a new string for every
     34        character; the new way still isn't all that efficient, but it's better. Also
     35        changed to use strchr instead of WTF::String::find for special characters.
     36
     37        * inspector/InspectorStyleSheet.cpp:
     38        (WebCore::InspectorStyle::newLineAndWhitespaceDelimiters): Use WTF::String's
     39        [] operator instead of an explicit call to the characters function.
     40        * inspector/InspectorStyleTextEditor.cpp:
     41        (WebCore::InspectorStyleTextEditor::insertProperty): Ditto.
     42        (WebCore::InspectorStyleTextEditor::internalReplaceProperty): Ditto.
     43        * platform/Length.cpp:
     44        (WebCore::newCoordsArray): Ditto.
     45
     46        * platform/LinkHash.cpp:
     47        (WebCore::visitedLinkHash): Use characters16 instead of characters since
     48        we have already checked is8Bit. Replace the length check with a check of
     49        isNull (as above in parseHTMLNonNegativeInteger).
     50
     51        * platform/graphics/Color.cpp:
     52        (WebCore::Color::parseHexColor): Use characters16 since we already checked is8Bit.
     53        (WebCore::Color::Color): Ditto.
     54
     55        * platform/graphics/TextRun.h:
     56        (WebCore::TextRun::TextRun): Use characters16 instead of characters since
     57        we have already checked is8Bit. Replace the length check with a check of
     58        isNull (as above in parseHTMLNonNegativeInteger).
     59
     60        * platform/text/TextEncodingRegistry.cpp:
     61        (WebCore::atomicCanonicalTextEncodingName): Use characters16 instead of
     62        characters since we already checked is8Bit. Also use isEmpty instead of !length.
     63
     64        * rendering/RenderBlock.cpp:
     65        (WebCore::RenderBlock::constructTextRun): Use characters16 instead of characters
     66        since we have already checked is8Bit. Replace the length check with a check of
     67        isNull (as above in parseHTMLNonNegativeInteger).
     68
     69        * rendering/RenderCombineText.cpp:
     70        (WebCore::RenderCombineText::width): Check for zero length instead of checking
     71        for null characters.
     72
     73        * svg/SVGFontElement.cpp:
     74        (WebCore::SVGFontElement::registerLigaturesInGlyphCache): Rewrite ligatures
     75        for loop and give local variables a better name. Construct the substring with
     76        the substring function. Still a really inefficient approach -- allocating a new
     77        string for every character is absurdly expensive.
     78
     79        * xml/XPathFunctions.cpp:
     80        (WebCore::XPath::FunId::evaluate): Use String instead of StringBuilder. Still
     81        not all that efficient, but better than before. Use substring to construct the
     82        substring.
     83
     84        * xml/XPathNodeSet.h: Added begin and end functions so we can use a C++11 for
     85        loop with this class.
     86
    1872014-01-12  Benjamin Poulain  <benjamin@webkit.org>
    288
  • trunk/Source/WebCore/bindings/objc/WebScriptObject.mm

    r161220 r161840  
    549549    }
    550550
    551     if (value.isString()) {
    552         ExecState* exec = rootObject->globalObject()->globalExec();
    553         const String& u = asString(value)->value(exec);
    554         return [NSString stringWithCharacters:u.characters() length:u.length()];
    555     }
     551    if (value.isString())
     552        return asString(value)->value(rootObject->globalObject()->globalExec());
    556553
    557554    if (value.isNumber())
  • trunk/Source/WebCore/editing/CompositeEditCommand.cpp

    r161638 r161840  
    668668{
    669669    for (unsigned i = 0; i < text.length(); ++i) {
    670         if (!isWhitespace(text.characters()[i]))
     670        if (!isWhitespace(text[i]))
    671671            return false;
    672672    }
    673    
    674673    return true;
    675674}
  • trunk/Source/WebCore/editing/TypingCommand.cpp

    r161638 r161840  
    153153
    154154    if (!text.isEmpty())
    155         frame->editor().updateMarkersForWordsAffectedByEditing(isSpaceOrNewline(text.characters()[0]));
     155        frame->editor().updateMarkersForWordsAffectedByEditing(isSpaceOrNewline(text[0]));
    156156   
    157157    insertText(document, text, frame->selection().selection(), options, composition);
  • trunk/Source/WebCore/editing/VisibleUnits.cpp

    r161795 r161840  
    11471147            type = Position::PositionIsOffsetInAnchor;
    11481148            if (style.preserveNewline()) {
    1149                 const UChar* chars = toRenderText(r)->characters();
    1150                 int i = toRenderText(r)->textLength();
    1151                 int o = offset;
    1152                 if (n == startNode && o < i)
    1153                     i = std::max(0, o);
    1154                 while (--i >= 0) {
    1155                     if (chars[i] == '\n')
    1156                         return VisiblePosition(Position(toText(n), i + 1), DOWNSTREAM);
    1157                 }
     1149                unsigned startOffset = n == startNode ? std::max(0, offset) : std::numeric_limits<unsigned>::max();
     1150                size_t newlineOffset = toRenderText(r)->text()->reverseFind('\n', startOffset);
     1151                if (newlineOffset != notFound)
     1152                    return VisiblePosition(Position(toText(n), newlineOffset + 1), DOWNSTREAM);
    11581153            }
    11591154            node = n;
     
    12271222        if (r->isText() && toRenderText(r)->hasRenderedText()) {
    12281223            ASSERT_WITH_SECURITY_IMPLICATION(n->isTextNode());
    1229             int length = toRenderText(r)->textLength();
    12301224            type = Position::PositionIsOffsetInAnchor;
    12311225            if (style.preserveNewline()) {
    1232                 const UChar* chars = toRenderText(r)->characters();
    1233                 int o = n == startNode ? offset : 0;
    1234                 for (int i = o; i < length; ++i) {
    1235                     if (chars[i] == '\n')
    1236                         return VisiblePosition(Position(toText(n), i), DOWNSTREAM);
    1237                 }
     1226                size_t newlineOffset = toRenderText(r)->text()->find('\n', n == startNode ? offset : 0);
     1227                if (newlineOffset != notFound)
     1228                    return VisiblePosition(Position(toText(n), newlineOffset), DOWNSTREAM);
    12381229            }
    12391230            node = n;
  • trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp

    r158650 r161840  
    7272        return stripLeadingAndTrailingHTMLSpaces(string, string.characters8(), length);
    7373
    74     return stripLeadingAndTrailingHTMLSpaces(string, string.characters(), length);
     74    return stripLeadingAndTrailingHTMLSpaces(string, string.characters16(), length);
    7575}
    7676
     
    268268    // Step 2
    269269    unsigned length = input.length();
    270     if (length && input.is8Bit()) {
     270    if (input.isNull() || input.is8Bit()) {
    271271        const LChar* start = input.characters8();
    272272        return parseHTMLNonNegativeIntegerInternal(start, start + length, value);
    273273    }
    274274   
    275     const UChar* start = input.characters();
     275    const UChar* start = input.characters16();
    276276    return parseHTMLNonNegativeIntegerInternal(start, start + length, value);
    277277}
  • trunk/Source/WebCore/inspector/ContentSearchUtils.cpp

    r161309 r161840  
    3737#include <wtf/BumpPointerAllocator.h>
    3838#include <wtf/StdLibExtras.h>
     39#include <wtf/text/StringBuilder.h>
    3940#include <yarr/Yarr.h>
    4041
     
    5152static String createSearchRegexSource(const String& text)
    5253{
    53     String result;
    54     const UChar* characters = text.characters();
    55     String specials(regexSpecialCharacters);
    56 
     54    StringBuilder result;
    5755    for (unsigned i = 0; i < text.length(); i++) {
    58         if (specials.find(characters[i]) != notFound)
    59             result.append("\\");
    60         result.append(characters[i]);
    61     }
    62 
    63     return result;
     56        if (isASCII(text[i]) && strchr(regexSpecialCharacters, text[i]))
     57            result.append('\\');
     58        result.append(text[i]);
     59    }
     60    return result.toString();
    6461}
    6562
  • trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp

    r160457 r161840  
    724724    bool isFullPrefixScanned = false;
    725725    bool lineFeedTerminated = false;
    726     const UChar* characters = text.characters();
    727726    while (propertyIndex < propertyCount) {
    728727        const WebCore::CSSPropertySourceData& currentProperty = sourcePropertyData->at(propertyIndex++);
     
    731730        int scanEnd = currentProperty.range.start;
    732731        for (int i = scanStart; i < scanEnd; ++i) {
    733             UChar ch = characters[i];
     732            UChar ch = text[i];
    734733            bool isLineFeed = isHTMLLineBreak(ch);
    735734            if (isLineFeed) {
  • trunk/Source/WebCore/inspector/InspectorStyleTextEditor.cpp

    r160457 r161840  
    8383        propertyStart = styleBodyLength;
    8484        if (propertyStart && textToSet.length()) {
    85             const UChar* characters = m_styleText.characters();
    86 
    8785            long curPos = propertyStart - 1; // The last position of style declaration, since propertyStart points past one.
    88             while (curPos && isHTMLSpace(characters[curPos]))
     86            while (curPos && isHTMLSpace(m_styleText[curPos]))
    8987                --curPos;
    90             if (curPos && characters[curPos] != ';') {
     88            if (curPos && m_styleText[curPos] != ';') {
    9189                // Prepend a ";" to the property text if appending to a style declaration where
    9290                // the last property has no trailing ";".
     
    231229    long replaceRangeStart = range.start;
    232230    long replaceRangeEnd = range.end;
    233     const UChar* characters = m_styleText.characters();
    234231    long newTextLength = newText.length();
    235232    String finalNewText = newText;
     
    242239            replaceRangeStart -= fullPrefixLength;
    243240    } else if (newTextLength) {
    244         if (isHTMLLineBreak(newText.characters()[newTextLength - 1])) {
     241        if (isHTMLLineBreak(newText[newTextLength - 1])) {
    245242            // Coalesce newlines of the original and new property values (to avoid a lot of blank lines while incrementally applying property values).
    246243            bool foundNewline = false;
     
    248245            int i;
    249246            int textLength = m_styleText.length();
    250             for (i = replaceRangeEnd; i < textLength && isSpaceOrNewline(characters[i]); ++i) {
    251                 isLastNewline = isHTMLLineBreak(characters[i]);
     247            for (i = replaceRangeEnd; i < textLength && isSpaceOrNewline(m_styleText[i]); ++i) {
     248                isLastNewline = isHTMLLineBreak(m_styleText[i]);
    252249                if (isLastNewline)
    253250                    foundNewline = true;
  • trunk/Source/WebCore/platform/Length.cpp

    r156132 r161840  
    8989{
    9090    unsigned length = string.length();
    91     const UChar* data = string.characters();
    9291    StringBuffer<UChar> spacified(length);
    9392    for (unsigned i = 0; i < length; i++) {
    94         UChar cc = data[i];
     93        UChar cc = string[i];
    9594        if (cc > '9' || (cc < '0' && cc != '-' && cc != '*' && cc != '.'))
    9695            spacified[i] = ' ';
  • trunk/Source/WebCore/platform/LinkHash.cpp

    r156550 r161840  
    215215{
    216216    unsigned length = url.length();
    217 
    218     if (length && url.is8Bit())
     217    if (url.isNull() || url.is8Bit())
    219218        return visitedLinkHashInline(url.characters8(), length);
    220     return visitedLinkHashInline(url.characters(), length);
     219    return visitedLinkHashInline(url.characters16(), length);
    221220}
    222221
  • trunk/Source/WebCore/platform/graphics/Color.cpp

    r161589 r161840  
    166166    if (name.is8Bit())
    167167        return parseHexColor(name.characters8(), name.length(), rgb);
    168     return parseHexColor(name.characters(), name.length(), rgb);
     168    return parseHexColor(name.characters16(), name.length(), rgb);
    169169}
    170170
     
    183183            m_valid = parseHexColor(name.characters8() + 1, name.length() - 1, m_color);
    184184        else
    185             m_valid = parseHexColor(name.characters() + 1, name.length() - 1, m_color);
     185            m_valid = parseHexColor(name.characters16() + 1, name.length() - 1, m_color);
    186186    } else
    187187        setNamedColor(name);
  • trunk/Source/WebCore/platform/graphics/TextRun.h

    r157960 r161840  
    125125    {
    126126#if ENABLE(8BIT_TEXTRUN)
    127         if (m_charactersLength && s.is8Bit()) {
     127        if (s.isNull() || s.is8Bit()) {
    128128            m_data.characters8 = s.characters8();
    129129            m_is8Bit = true;
    130130        } else {
    131             m_data.characters16 = s.characters();
     131            m_data.characters16 = s.characters16();
    132132            m_is8Bit = false;
    133133        }
  • trunk/Source/WebCore/platform/text/TextEncodingRegistry.cpp

    r161589 r161840  
    344344const char* atomicCanonicalTextEncodingName(const String& alias)
    345345{
    346     if (!alias.length())
    347         return 0;
     346    if (alias.isEmpty())
     347        return nullptr;
    348348
    349349    if (alias.is8Bit())
    350350        return atomicCanonicalTextEncodingName<LChar>(alias.characters8(), alias.length());
    351351
    352     return atomicCanonicalTextEncodingName<UChar>(alias.characters(), alias.length());
     352    return atomicCanonicalTextEncodingName<UChar>(alias.characters16(), alias.length());
    353353}
    354354
  • trunk/Source/WebCore/rendering/RenderBlock.cpp

    r161790 r161840  
    54805480{
    54815481    unsigned length = string.length();
    5482 
    54835482#if ENABLE(8BIT_TEXTRUN)
    5484     if (length && string.is8Bit())
     5483    if (string.isNull() || string.is8Bit())
    54855484        return constructTextRunInternal(context, font, string.characters8(), length, style, expansion, flags);
    5486     return constructTextRunInternal(context, font, string.characters(), length, style, expansion, flags);
     5485    return constructTextRunInternal(context, font, string.characters16(), length, style, expansion, flags);
    54875486#else
    54885487    return constructTextRunInternal(context, font, string.characters(), length, style, expansion, flags);
  • trunk/Source/WebCore/rendering/RenderCombineText.cpp

    r158163 r161840  
    6161float RenderCombineText::width(unsigned from, unsigned length, const Font& font, float xPosition, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow* glyphOverflow) const
    6262{
    63     if (!characters())
     63    if (!textLength())
    6464        return 0;
    6565
  • trunk/Source/WebCore/svg/SVGFontElement.cpp

    r160598 r161840  
    8888    // character substitution properly through glyphDataForCharacter().
    8989    Vector<SVGGlyph> glyphs;
    90     size_t ligaturesSize = ligatures.size();
    91     for (size_t i = 0; i < ligaturesSize; ++i) {
    92         const String& unicode = ligatures[i];
    93 
    94         unsigned unicodeLength = unicode.length();
    95         ASSERT(unicodeLength > 1);
    96 
    97         const UChar* characters = unicode.characters();
    98         for (unsigned i = 0; i < unicodeLength; ++i) {
    99             String lookupString(characters + i, 1);
     90    for (auto& ligature : ligatures) {
     91        unsigned ligatureLength = ligature.length();
     92        ASSERT(ligatureLength > 1);
     93
     94        for (unsigned i = 0; i < ligatureLength; ++i) {
     95            // FIXME: Is there a faster way to do this without allocating/deallocating a string for every character in every ligature?
     96            String lookupString(ligature.substring(i, 1));
    10097            m_glyphMap.collectGlyphsForString(lookupString, glyphs);
    10198            if (!glyphs.isEmpty()) {
  • trunk/Source/WebCore/xml/XPathFunctions.cpp

    r161425 r161840  
    308308{
    309309    Value a = argument(0).evaluate();
    310     StringBuilder idList; // A whitespace-separated list of IDs
    311 
     310
     311    String idList; // A whitespace-separated list of IDs
    312312    if (a.isNodeSet()) {
    313         const NodeSet& nodes = a.toNodeSet();
    314         for (size_t i = 0; i < nodes.size(); ++i) {
    315             String str = stringValue(nodes[i]);
    316             idList.append(str);
    317             idList.append(' ');
     313        StringBuilder spaceSeparatedList;
     314        for (auto& node : a.toNodeSet()) {
     315            spaceSeparatedList.append(stringValue(node.get()));
     316            spaceSeparatedList.append(' ');
    318317        }
     318        idList = spaceSeparatedList.toString();
    319319    } else {
    320         String str = a.toString();
    321         idList.append(str);
     320        idList = a.toString();
    322321    }
    323322   
     
    341340        // If there are several nodes with the same id, id() should return the first one.
    342341        // In WebKit, getElementById behaves so, too, although its behavior in this case is formally undefined.
    343         Node* node = contextScope.getElementById(String(idList.characters() + startPos, endPos - startPos));
     342        Node* node = contextScope.getElementById(idList.substring(startPos, endPos - startPos));
    344343        if (node && resultSet.add(node).isNewEntry)
    345344            result.append(node);
  • trunk/Source/WebCore/xml/XPathNodeSet.h

    r157205 r161840  
    4545            void clear() { m_nodes.clear(); }
    4646
     47            Vector<RefPtr<Node>>::const_iterator begin() const { return m_nodes.begin(); }
     48            Vector<RefPtr<Node>>::const_iterator end() const { return m_nodes.end(); }
     49
    4750            // NodeSet itself does not verify that nodes in it are unique.
    4851            void append(PassRefPtr<Node> node) { m_nodes.append(node); }
Note: See TracChangeset for help on using the changeset viewer.