Avoid upconverting strings in various places in WebCore
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 14 Jul 2013 01:11:43 +0000 (01:11 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 14 Jul 2013 01:11:43 +0000 (01:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=118632

Reviewed by Andreas Kling.

Avoid calling String::characters() in various places since it upconverts 8-bit strings to 16-bit strings.

Merge
https://chromium.googlesource.com/chromium/blink/+/a6162e2ad7c7870e22445d3c463d17e7ac871e80
https://chromium.googlesource.com/chromium/blink/+/18095209b3f467758b83894e7b14f813f6953f81
https://chromium.googlesource.com/chromium/blink/+/fefcf2b95d55f24c60fd2e95978cf4544f3c92ca
https://chromium.googlesource.com/chromium/blink/+/8e0527b0fb33998318aedfd74b3511025f7ff294
https://chromium.googlesource.com/chromium/blink/+/feaf798b04597b0849b4000fc305264895d3eac5
https://chromium.googlesource.com/chromium/blink/+/bd1a49103a6e07b1023d2c742d8217769efbffb4

* css/CSSParser.cpp:
(WebCore::CSSParser::setupParser):
(WebCore::CSSParser::parseImageSet):
(WebCore::CSSParser::rewriteSpecifiers):
* css/CSSParserValues.h:
(WebCore::CSSParserString::init):
(WebCore::CSSParserString::clear):
* dom/DatasetDOMStringMap.cpp:
(WebCore::isValidAttributeName):
(WebCore::convertAttributeNameToPropertyName):
(WebCore::propertyNameMatchesAttributeName):
(WebCore::isValidPropertyName):
(WebCore::convertPropertyNameToAttributeName):
* dom/Range.cpp:
(WebCore::Range::toString):
* dom/SecurityContext.cpp:
(WebCore::SecurityContext::parseSandboxPolicy):
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::measureText):
* html/track/TextTrackCue.cpp:
(WebCore::TextTrackCue::markFutureAndPastNodes):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@152611 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/CSSParserValues.h
Source/WebCore/dom/DatasetDOMStringMap.cpp
Source/WebCore/dom/Range.cpp
Source/WebCore/dom/SecurityContext.cpp
Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
Source/WebCore/html/track/TextTrackCue.cpp

index ee5e109..6fccee6 100644 (file)
@@ -1,5 +1,44 @@
 2013-07-13  Ryosuke Niwa  <rniwa@webkit.org>
 
+        Avoid upconverting strings in various places in WebCore
+        https://bugs.webkit.org/show_bug.cgi?id=118632
+
+        Reviewed by Andreas Kling.
+
+        Avoid calling String::characters() in various places since it upconverts 8-bit strings to 16-bit strings.
+
+        Merge
+        https://chromium.googlesource.com/chromium/blink/+/a6162e2ad7c7870e22445d3c463d17e7ac871e80
+        https://chromium.googlesource.com/chromium/blink/+/18095209b3f467758b83894e7b14f813f6953f81
+        https://chromium.googlesource.com/chromium/blink/+/fefcf2b95d55f24c60fd2e95978cf4544f3c92ca
+        https://chromium.googlesource.com/chromium/blink/+/8e0527b0fb33998318aedfd74b3511025f7ff294
+        https://chromium.googlesource.com/chromium/blink/+/feaf798b04597b0849b4000fc305264895d3eac5
+        https://chromium.googlesource.com/chromium/blink/+/bd1a49103a6e07b1023d2c742d8217769efbffb4
+
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::setupParser):
+        (WebCore::CSSParser::parseImageSet):
+        (WebCore::CSSParser::rewriteSpecifiers):
+        * css/CSSParserValues.h:
+        (WebCore::CSSParserString::init):
+        (WebCore::CSSParserString::clear):
+        * dom/DatasetDOMStringMap.cpp:
+        (WebCore::isValidAttributeName):
+        (WebCore::convertAttributeNameToPropertyName):
+        (WebCore::propertyNameMatchesAttributeName):
+        (WebCore::isValidPropertyName):
+        (WebCore::convertPropertyNameToAttributeName):
+        * dom/Range.cpp:
+        (WebCore::Range::toString):
+        * dom/SecurityContext.cpp:
+        (WebCore::SecurityContext::parseSandboxPolicy):
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::measureText):
+        * html/track/TextTrackCue.cpp:
+        (WebCore::TextTrackCue::markFutureAndPastNodes):
+
+2013-07-13  Ryosuke Niwa  <rniwa@webkit.org>
+
         parseHTMLInteger shouldn't upconvert 8-bit string
         https://bugs.webkit.org/show_bug.cgi?id=118629
 
index 885ae2d..1d2d0ca 100644 (file)
@@ -436,7 +436,8 @@ void CSSParser::setupParser(const char* prefix, unsigned prefixLength, const Str
     for (unsigned i = 0; i < m_parsedTextPrefixLength; i++)
         m_dataStart16[i] = prefix[i];
 
-    memcpy(m_dataStart16.get() + m_parsedTextPrefixLength, string.characters(), stringLength * sizeof(UChar));
+    ASSERT(stringLength);
+    memcpy(m_dataStart16.get() + m_parsedTextPrefixLength, string.characters16(), stringLength * sizeof(UChar));
 
     unsigned start = m_parsedTextPrefixLength + stringLength;
     unsigned end = start + suffixLength;
@@ -8059,7 +8060,7 @@ PassRefPtr<CSSValue> CSSParser::parseImageSet()
             const LChar* start = string.characters8();
             parseDouble(start, start + length, 'x', imageScaleFactor);
         } else {
-            const UChar* start = string.characters();
+            const UChar* start = string.characters16();
             parseDouble(start, start + length, 'x', imageScaleFactor);
         }
         if (imageScaleFactor <= 0)
@@ -12202,7 +12203,7 @@ CSSPropertyID cssPropertyID(const String& string)
     if (length > maxCSSPropertyNameLength)
         return CSSPropertyInvalid;
     
-    return string.is8Bit() ? cssPropertyID(string.characters8(), length) : cssPropertyID(string.characters(), length);
+    return string.is8Bit() ? cssPropertyID(string.characters8(), length) : cssPropertyID(string.characters16(), length);
 }
 
 CSSPropertyID cssPropertyID(const CSSParserString& string)
@@ -12300,7 +12301,7 @@ static bool isCSSTokenizerIdentifier(const String& string)
 
     if (string.is8Bit())
         return isCSSTokenizerIdentifier(string.characters8(), length);
-    return isCSSTokenizerIdentifier(string.characters(), length);
+    return isCSSTokenizerIdentifier(string.characters16(), length);
 }
 
 template <typename CharacterType>
@@ -12340,7 +12341,7 @@ static bool isCSSTokenizerURL(const String& string)
 
     if (string.is8Bit())
         return isCSSTokenizerURL(string.characters8(), length);
-    return isCSSTokenizerURL(string.characters(), length);
+    return isCSSTokenizerURL(string.characters16(), length);
 }
 
 
index 1fd9534..b899e1c 100644 (file)
@@ -50,11 +50,11 @@ struct CSSParserString {
     void init(const String& string)
     {
         m_length = string.length();
-        if (m_length && string.is8Bit()) {
+        if (!m_length || string.is8Bit()) {
             m_data.characters8 = const_cast<LChar*>(string.characters8());
             m_is8Bit = true;
         } else {
-            m_data.characters16 = const_cast<UChar*>(string.characters());
+            m_data.characters16 = const_cast<UChar*>(string.characters16());
             m_is8Bit = false;
         }
     }
@@ -63,7 +63,7 @@ struct CSSParserString {
     {
         m_data.characters8 = 0;
         m_length = 0;
-        m_is8Bit = false;
+        m_is8Bit = true;
     }
 
     bool is8Bit() const { return m_is8Bit; }
index d82c8bc..adf3b78 100644 (file)
@@ -39,10 +39,9 @@ static bool isValidAttributeName(const String& name)
     if (!name.startsWith("data-"))
         return false;
 
-    const UChar* characters = name.characters();
     unsigned length = name.length();
     for (unsigned i = 5; i < length; ++i) {
-        if (isASCIIUpper(characters[i]))
+        if (isASCIIUpper(name[i]))
             return false;
     }
 
@@ -53,15 +52,14 @@ static String convertAttributeNameToPropertyName(const String& name)
 {
     StringBuilder stringBuilder;
 
-    const UChar* characters = name.characters();
     unsigned length = name.length();
     for (unsigned i = 5; i < length; ++i) {
-        UChar character = characters[i];
+        UChar character = name[i];
         if (character != '-')
             stringBuilder.append(character);
         else {
-            if ((i + 1 < length) && isASCIILower(characters[i + 1])) {
-                stringBuilder.append(toASCIIUpper(characters[i + 1]));
+            if ((i + 1 < length) && isASCIILower(name[i + 1])) {
+                stringBuilder.append(toASCIIUpper(name[i + 1]));
                 ++i;
             } else
                 stringBuilder.append(character);
@@ -76,19 +74,18 @@ static bool propertyNameMatchesAttributeName(const String& propertyName, const S
     if (!attributeName.startsWith("data-"))
         return false;
 
-    const UChar* property = propertyName.characters();
-    const UChar* attribute = attributeName.characters();
     unsigned propertyLength = propertyName.length();
     unsigned attributeLength = attributeName.length();
-   
+
     unsigned a = 5;
     unsigned p = 0;
     bool wordBoundary = false;
     while (a < attributeLength && p < propertyLength) {
-        if (attribute[a] == '-' && a + 1 < attributeLength && attribute[a + 1] != '-')
+        const UChar currentAttributeNameChar = attributeName[a];
+        if (currentAttributeNameChar == '-' && a + 1 < attributeLength && attributeName[a + 1] != '-')
             wordBoundary = true;
         else {
-            if ((wordBoundary ? toASCIIUpper(attribute[a]) : attribute[a]) != property[p])
+            if ((wordBoundary ? toASCIIUpper(currentAttributeNameChar) : currentAttributeNameChar) != propertyName[p])
                 return false;
             p++;
             wordBoundary = false;
@@ -101,10 +98,9 @@ static bool propertyNameMatchesAttributeName(const String& propertyName, const S
 
 static bool isValidPropertyName(const String& name)
 {
-    const UChar* characters = name.characters();
     unsigned length = name.length();
     for (unsigned i = 0; i < length; ++i) {
-        if (characters[i] == '-' && (i + 1 < length) && isASCIILower(characters[i + 1]))
+        if (name[i] == '-' && (i + 1 < length) && isASCIILower(name[i + 1]))
             return false;
     }
     return true;
@@ -115,10 +111,9 @@ static String convertPropertyNameToAttributeName(const String& name)
     StringBuilder builder;
     builder.append("data-");
 
-    const UChar* characters = name.characters();
     unsigned length = name.length();
     for (unsigned i = 0; i < length; ++i) {
-        UChar character = characters[i];
+        UChar character = name[i];
         if (isASCIIUpper(character)) {
             builder.append('-');
             builder.append(toASCIILower(character));
index c65f68a..a90872c 100644 (file)
@@ -1066,11 +1066,11 @@ String Range::toString(ExceptionCode& ec) const
     Node* pastLast = pastLastNode();
     for (Node* n = firstNode(); n != pastLast; n = NodeTraversal::next(n)) {
         if (n->nodeType() == Node::TEXT_NODE || n->nodeType() == Node::CDATA_SECTION_NODE) {
-            String data = static_cast<CharacterData*>(n)->data();
+            const String& data = static_cast<CharacterData*>(n)->data();
             int length = data.length();
             int start = (n == m_start.container()) ? min(max(0, m_start.offset()), length) : 0;
             int end = (n == m_end.container()) ? min(max(start, m_end.offset()), length) : length;
-            builder.append(data.characters() + start, end - start);
+            builder.append(data, start, end - start);
         }
     }
 
index 394a68f..74d3e3b 100644 (file)
@@ -82,18 +82,17 @@ SandboxFlags SecurityContext::parseSandboxPolicy(const String& policy, String& i
     // http://www.w3.org/TR/html5/the-iframe-element.html#attr-iframe-sandbox
     // Parse the unordered set of unique space-separated tokens.
     SandboxFlags flags = SandboxAll;
-    const UChar* characters = policy.characters();
     unsigned length = policy.length();
     unsigned start = 0;
     unsigned numberOfTokenErrors = 0;
     StringBuilder tokenErrors;
     while (true) {
-        while (start < length && isHTMLSpace(characters[start]))
+        while (start < length && isHTMLSpace(policy[start]))
             ++start;
         if (start >= length)
             break;
         unsigned end = start + 1;
-        while (end < length && !isHTMLSpace(characters[end]))
+        while (end < length && !isHTMLSpace(policy[end]))
             ++end;
 
         // Turn off the corresponding sandbox flag if it's set as "allowed".
index 5e0469f..caae0ba 100644 (file)
@@ -2113,7 +2113,7 @@ PassRefPtr<TextMetrics> CanvasRenderingContext2D::measureText(const String& text
     Font::setCodePath(Font::Complex);
 #endif
 
-    metrics->setWidth(accessFont().width(TextRun(text.characters(), text.length())));
+    metrics->setWidth(accessFont().width(TextRun(text)));
 
 #if PLATFORM(QT)
     Font::setCodePath(oldCodePath);
index 67e39f6..aa85ce1 100644 (file)
@@ -776,7 +776,7 @@ void TextTrackCue::markFutureAndPastNodes(ContainerNode* root, double previousTi
             toWebVTTElement(child)->setIsPastNode(isPastNode);
             // Make an elemenet id match a cue id for style matching purposes.
             if (!m_id.isEmpty())
-                toElement(child)->setIdAttribute(AtomicString(m_id.characters(), m_id.length()));
+                toElement(child)->setIdAttribute(m_id);
         }
     }
 }