Title: [102059] trunk/Source
Revision
102059
Author
[email protected]
Date
2011-12-05 15:56:49 -0800 (Mon, 05 Dec 2011)

Log Message

Update String::containsOnlyASCII() to handle 8 bits strings
https://bugs.webkit.org/show_bug.cgi?id=73799

Reviewed by Darin Adler.

Source/_javascript_Core: 

Implement String::containsOnlyASCII() so that it does not
call String::characters().

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

Source/WebCore: 

When possible, change the call sites from charactersAreAllASCII()
to the optimized version String::containsOnlyASCII().

* platform/KURL.cpp:
(WebCore::KURL::init):
* platform/cf/BinaryPropertyList.cpp:
(WebCore::BinaryPropertyListPlan::writeStringObject):
* platform/graphics/chromium/FontCacheChromiumWin.cpp:
(WebCore::FontCodepage::if):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (102058 => 102059)


--- trunk/Source/_javascript_Core/ChangeLog	2011-12-05 23:54:02 UTC (rev 102058)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-12-05 23:56:49 UTC (rev 102059)
@@ -1,3 +1,16 @@
+2011-12-05  Benjamin Poulain  <[email protected]>
+
+        Update String::containsOnlyASCII() to handle 8 bits strings
+        https://bugs.webkit.org/show_bug.cgi?id=73799
+
+        Reviewed by Darin Adler.
+
+        Implement String::containsOnlyASCII() so that it does not
+        call String::characters().
+
+        * wtf/text/WTFString.h:
+        (WTF::String::containsOnlyASCII):
+
 2011-12-05  Filip Pizlo  <[email protected]>
 
         Unreviewed build fix for non-DFG platforms.

Modified: trunk/Source/_javascript_Core/wtf/text/WTFString.h (102058 => 102059)


--- trunk/Source/_javascript_Core/wtf/text/WTFString.h	2011-12-05 23:54:02 UTC (rev 102058)
+++ trunk/Source/_javascript_Core/wtf/text/WTFString.h	2011-12-05 23:56:49 UTC (rev 102059)
@@ -61,7 +61,7 @@
 
 // Declarations of string operations
 
-bool charactersAreAllASCII(const UChar*, size_t);
+template<typename CharType> inline bool charactersAreAllASCII(const CharType* characters, size_t length);
 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);
@@ -373,7 +373,7 @@
         return WTF::Unicode::LeftToRight;
     }
 
-    bool containsOnlyASCII() const { return charactersAreAllASCII(characters(), length()); }
+    bool containsOnlyASCII() const;
     bool containsOnlyLatin1() const;
     bool containsOnlyWhitespace() const { return !m_impl || m_impl->containsOnlyWhitespace(); }
 
@@ -482,14 +482,28 @@
 inline NSString* nsStringNilIfEmpty(const String& str) {  return str.isEmpty() ? nil : (NSString*)str; }
 #endif
 
-inline bool charactersAreAllASCII(const UChar* characters, size_t length)
+template<typename CharType>
+inline bool charactersAreAllASCII(const CharType* characters, size_t length)
 {
-    UChar ored = 0;
+    CharType ored = 0;
     for (size_t i = 0; i < length; ++i)
         ored |= characters[i];
-    return !(ored & 0xFF80);
+
+    CharType lowBits = 0x7F;
+    return !(ored & ~lowBits);
 }
 
+inline bool String::containsOnlyASCII() const
+{
+    if (isEmpty())
+        return true;
+
+    if (is8Bit())
+        return charactersAreAllASCII(characters8(), m_impl->length());
+
+    return charactersAreAllASCII(characters16(), m_impl->length());
+}
+
 WTF_EXPORT_PRIVATE int codePointCompare(const String&, const String&);
 
 inline size_t find(const LChar* characters, unsigned length, LChar matchCharacter, unsigned index = 0)

Modified: trunk/Source/WebCore/ChangeLog (102058 => 102059)


--- trunk/Source/WebCore/ChangeLog	2011-12-05 23:54:02 UTC (rev 102058)
+++ trunk/Source/WebCore/ChangeLog	2011-12-05 23:56:49 UTC (rev 102059)
@@ -1,3 +1,20 @@
+2011-12-05  Benjamin Poulain  <[email protected]>
+
+        Update String::containsOnlyASCII() to handle 8 bits strings
+        https://bugs.webkit.org/show_bug.cgi?id=73799
+
+        Reviewed by Darin Adler.
+
+        When possible, change the call sites from charactersAreAllASCII()
+        to the optimized version String::containsOnlyASCII().
+
+        * platform/KURL.cpp:
+        (WebCore::KURL::init):
+        * platform/cf/BinaryPropertyList.cpp:
+        (WebCore::BinaryPropertyListPlan::writeStringObject):
+        * platform/graphics/chromium/FontCacheChromiumWin.cpp:
+        (WebCore::FontCodepage::if):
+
 2011-12-01  Vangelis Kokkevis  <[email protected]>
 
         [chromium] Use ANGLE's texture_usage and texture_storage extensions when allocating compositor textures

Modified: trunk/Source/WebCore/platform/KURL.cpp (102058 => 102059)


--- trunk/Source/WebCore/platform/KURL.cpp	2011-12-05 23:54:02 UTC (rev 102058)
+++ trunk/Source/WebCore/platform/KURL.cpp	2011-12-05 23:56:49 UTC (rev 102059)
@@ -376,7 +376,7 @@
     if (rel.contains('\\') && !(protocolIsJavaScript(rel) || protocolIs(rel, "data")))
         rel = substituteBackslashes(rel);
 
-    bool allASCII = charactersAreAllASCII(rel.characters(), rel.length());
+    bool allASCII = rel.containsOnlyASCII();
     CharBuffer strBuffer;
     char* str;
     size_t len;

Modified: trunk/Source/WebCore/platform/cf/BinaryPropertyList.cpp (102058 => 102059)


--- trunk/Source/WebCore/platform/cf/BinaryPropertyList.cpp	2011-12-05 23:54:02 UTC (rev 102058)
+++ trunk/Source/WebCore/platform/cf/BinaryPropertyList.cpp	2011-12-05 23:56:49 UTC (rev 102059)
@@ -285,10 +285,9 @@
 
 void BinaryPropertyListPlan::writeStringObject(const String& string)
 {
-    const UChar* characters = string.characters();
     unsigned length = string.length();
     m_byteCount += markerPlusLengthByteCount(length) + length;
-    if (!charactersAreAllASCII(characters, length))
+    if (!string.containsOnlyASCII())
         m_byteCount += length;
 }
 

Modified: trunk/Source/WebCore/platform/graphics/chromium/FontCacheChromiumWin.cpp (102058 => 102059)


--- trunk/Source/WebCore/platform/graphics/chromium/FontCacheChromiumWin.cpp	2011-12-05 23:54:02 UTC (rev 102058)
+++ trunk/Source/WebCore/platform/graphics/chromium/FontCacheChromiumWin.cpp	2011-12-05 23:56:49 UTC (rev 102059)
@@ -50,12 +50,6 @@
 namespace WebCore
 {
 
-// FIXME: consider adding to WebKit String class
-static bool charactersAreAllASCII(const String& s)
-{
-    return WTF::charactersAreAllASCII(s.characters(), s.length());
-}
-
 // When asked for a CJK font with a native name under a non-CJK locale or
 // asked for a CJK font with a Romanized name under a CJK locale,
 // |GetTextFace| (after |CreateFont*|) returns a 'bogus' value (e.g. Arial).
@@ -216,7 +210,7 @@
     // use |lower| only for ASCII names 
     // For non-ASCII names, we don't want to invoke an expensive 
     // and unnecessary |lower|. 
-    if (charactersAreAllASCII(name)) {
+    if (name.containsOnlyASCII()) {
         isAscii = true;
         n = name.lower();
     } else
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to