Title: [153007] trunk/Source/WTF
Revision
153007
Author
[email protected]
Date
2013-07-22 15:29:03 -0700 (Mon, 22 Jul 2013)

Log Message

String::lower() - Skip to slow path on the first failure
https://bugs.webkit.org/show_bug.cgi?id=118885

Reviewed by Andreas Kling.

In the 8 bits case, we don't need to know the state of the full string before changing characters
to their lowercase variant.
Just fail immediately and start transforming characters from the point of failure.

This avoid reading the string twice when the uppercase character is not at the end of the string.

* wtf/text/StringImpl.cpp:
(WTF::StringImpl::lower):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (153006 => 153007)


--- trunk/Source/WTF/ChangeLog	2013-07-22 22:26:31 UTC (rev 153006)
+++ trunk/Source/WTF/ChangeLog	2013-07-22 22:29:03 UTC (rev 153007)
@@ -1,3 +1,19 @@
+2013-07-22  Benjamin Poulain  <[email protected]>
+
+        String::lower() - Skip to slow path on the first failure
+        https://bugs.webkit.org/show_bug.cgi?id=118885
+
+        Reviewed by Andreas Kling.
+
+        In the 8 bits case, we don't need to know the state of the full string before changing characters
+        to their lowercase variant.
+        Just fail immediately and start transforming characters from the point of failure.
+
+        This avoid reading the string twice when the uppercase character is not at the end of the string.
+
+        * wtf/text/StringImpl.cpp:
+        (WTF::StringImpl::lower):
+
 2013-07-22  Brent Fulgham  <[email protected]>
 
         [Windows] Unreviewed build fix.

Modified: trunk/Source/WTF/wtf/text/StringImpl.cpp (153006 => 153007)


--- trunk/Source/WTF/wtf/text/StringImpl.cpp	2013-07-22 22:26:31 UTC (rev 153006)
+++ trunk/Source/WTF/wtf/text/StringImpl.cpp	2013-07-22 22:29:03 UTC (rev 153007)
@@ -392,34 +392,35 @@
 
     // First scan the string for uppercase and non-ASCII characters:
     bool noUpper = true;
-    unsigned ored = 0;
     if (is8Bit()) {
+        unsigned failingIndex;
         for (unsigned i = 0; i < m_length; ++i) {
             LChar character = m_data8[i];
-            if (UNLIKELY(isASCIIUpper(character)))
-                noUpper = false;
-            ored |= character;
+            if (UNLIKELY((character & ~0x7F) || isASCIIUpper(character))) {
+                failingIndex = i;
+                goto SlowPath8bitLower;
+            }
         }
-        // Nothing to do if the string is all ASCII with no uppercase.
-        if (noUpper && !(ored & ~0x7F))
-            return this;
+        return this;
 
+SlowPath8bitLower:
         LChar* data8;
         RefPtr<StringImpl> newImpl = createUninitialized(m_length, data8);
 
-        if (!(ored & ~0x7F)) {
-            for (unsigned i = 0; i < m_length; ++i)
-                data8[i] = toASCIILower(m_data8[i]);
+        for (unsigned i = 0; i < failingIndex; ++i)
+            data8[i] = m_data8[i];
 
-            return newImpl.release();
+        for (unsigned i = failingIndex; i < m_length; ++i) {
+            LChar character = m_data8[i];
+            if (!(character & ~0x7F))
+                data8[i] = toASCIILower(character);
+            else
+                data8[i] = static_cast<LChar>(Unicode::toLower(character));
         }
 
-        // Do a slower implementation for cases that include non-ASCII Latin-1 characters.
-        for (unsigned i = 0; i < m_length; ++i)
-            data8[i] = static_cast<LChar>(Unicode::toLower(m_data8[i]));
-
         return newImpl.release();
     }
+    unsigned ored = 0;
 
     for (unsigned i = 0; i < m_length; ++i) {
         UChar character = m_data16[i];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to