Title: [102028] trunk/Source/_javascript_Core
Revision
102028
Author
[email protected]
Date
2011-12-05 12:27:47 -0800 (Mon, 05 Dec 2011)

Log Message

Update String::containsOnlyLatin1() to avoid converting to 16 bits
https://bugs.webkit.org/show_bug.cgi?id=73797

Reviewed by Andreas Kling.

When the String use 8bits StringImpl, there is no need to iterate
over the string.

The function charactersAreAllLatin1() is removed because it is not
used anywhere.

* wtf/text/WTFString.h:
(WTF::String::containsOnlyLatin1):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (102027 => 102028)


--- trunk/Source/_javascript_Core/ChangeLog	2011-12-05 20:08:59 UTC (rev 102027)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-12-05 20:27:47 UTC (rev 102028)
@@ -1,3 +1,19 @@
+2011-12-05  Benjamin Poulain  <[email protected]>
+
+        Update String::containsOnlyLatin1() to avoid converting to 16 bits
+        https://bugs.webkit.org/show_bug.cgi?id=73797
+
+        Reviewed by Andreas Kling.
+
+        When the String use 8bits StringImpl, there is no need to iterate
+        over the string.
+
+        The function charactersAreAllLatin1() is removed because it is not
+        used anywhere.
+
+        * wtf/text/WTFString.h:
+        (WTF::String::containsOnlyLatin1):
+
 2011-12-05  Michael Saboff  <[email protected]>
 
         8 bit string work slows down Kraken json-stringify-tinderbox

Modified: trunk/Source/_javascript_Core/wtf/text/WTFString.h (102027 => 102028)


--- trunk/Source/_javascript_Core/wtf/text/WTFString.h	2011-12-05 20:08:59 UTC (rev 102027)
+++ trunk/Source/_javascript_Core/wtf/text/WTFString.h	2011-12-05 20:27:47 UTC (rev 102028)
@@ -62,7 +62,6 @@
 // Declarations of string operations
 
 bool charactersAreAllASCII(const UChar*, size_t);
-bool charactersAreAllLatin1(const UChar*, size_t);
 WTF_EXPORT_PRIVATE int charactersToIntStrict(const LChar*, size_t, bool* ok = 0, int base = 10);
 WTF_EXPORT_PRIVATE int charactersToIntStrict(const UChar*, size_t, bool* ok = 0, int base = 10);
 WTF_EXPORT_PRIVATE unsigned charactersToUIntStrict(const LChar*, size_t, bool* ok = 0, int base = 10);
@@ -375,7 +374,7 @@
     }
 
     bool containsOnlyASCII() const { return charactersAreAllASCII(characters(), length()); }
-    bool containsOnlyLatin1() const { return charactersAreAllLatin1(characters(), length()); }
+    bool containsOnlyLatin1() const;
     bool containsOnlyWhitespace() const { return !m_impl || m_impl->containsOnlyWhitespace(); }
 
     // Hash table deleted values, which are only constructed and never copied or destroyed.
@@ -460,7 +459,22 @@
     return characters16();
 }
 
+inline bool String::containsOnlyLatin1() const
+{
+    if (isEmpty())
+        return true;
 
+    if (is8Bit())
+        return true;
+
+    const UChar* characters = characters16();
+    UChar ored = 0;
+    for (size_t i = 0; i < m_impl->length(); ++i)
+        ored |= characters[i];
+    return !(ored & 0xFF00);
+}
+
+
 #ifdef __OBJC__
 // This is for situations in WebKit where the long standing behavior has been
 // "nil if empty", so we try to maintain longstanding behavior for the sake of
@@ -476,14 +490,6 @@
     return !(ored & 0xFF80);
 }
 
-inline bool charactersAreAllLatin1(const UChar* characters, size_t length)
-{
-    UChar ored = 0;
-    for (size_t i = 0; i < length; ++i)
-        ored |= characters[i];
-    return !(ored & 0xFF00);
-}
-
 WTF_EXPORT_PRIVATE int codePointCompare(const String&, const String&);
 
 inline size_t find(const LChar* characters, unsigned length, LChar matchCharacter, unsigned index = 0)
@@ -610,7 +616,6 @@
 using WTF::append;
 using WTF::appendNumber;
 using WTF::charactersAreAllASCII;
-using WTF::charactersAreAllLatin1;
 using WTF::charactersToIntStrict;
 using WTF::charactersToUIntStrict;
 using WTF::charactersToInt64Strict;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to