Title: [132739] trunk/Source/WTF
Revision
132739
Author
[email protected]
Date
2012-10-27 13:33:17 -0700 (Sat, 27 Oct 2012)

Log Message

Try to create AtomicString as 8 bit where possible
https://bugs.webkit.org/show_bug.cgi?id=100575

Reviewed by Oliver Hunt.

Added StringImpl::create8BitIfPossible() that first tries to create an 8 bit string.  If it finds a 16 bit character
during processing, it calls the standard create() method.  The assumption is that this will be used on mostly 8 bit
strings and ones that are shorter (in the tens of characters).  Changed AtomicString to use the new creation method
for UChar based construction.

* wtf/text/AtomicString.cpp:
(WTF::UCharBufferTranslator::translate):
* wtf/text/StringImpl.cpp:
(WTF::StringImpl::create8BitIfPossible):
* wtf/text/StringImpl.h:
(WTF::StringImpl::create8BitIfPossible):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (132738 => 132739)


--- trunk/Source/WTF/ChangeLog	2012-10-27 20:31:04 UTC (rev 132738)
+++ trunk/Source/WTF/ChangeLog	2012-10-27 20:33:17 UTC (rev 132739)
@@ -1,5 +1,24 @@
 2012-10-27  Michael Saboff  <[email protected]>
 
+        Try to create AtomicString as 8 bit where possible
+        https://bugs.webkit.org/show_bug.cgi?id=100575
+
+        Reviewed by Oliver Hunt.
+
+        Added StringImpl::create8BitIfPossible() that first tries to create an 8 bit string.  If it finds a 16 bit character
+        during processing, it calls the standard create() method.  The assumption is that this will be used on mostly 8 bit
+        strings and ones that are shorter (in the tens of characters).  Changed AtomicString to use the new creation method
+        for UChar based construction.
+
+        * wtf/text/AtomicString.cpp:
+        (WTF::UCharBufferTranslator::translate):
+        * wtf/text/StringImpl.cpp:
+        (WTF::StringImpl::create8BitIfPossible):
+        * wtf/text/StringImpl.h:
+        (WTF::StringImpl::create8BitIfPossible):
+
+2012-10-27  Michael Saboff  <[email protected]>
+
         String::fromUTF8() should take advantage of the ASCII check in convertUTF8ToUTF16()
         https://bugs.webkit.org/show_bug.cgi?id=100577
 

Modified: trunk/Source/WTF/wtf/text/AtomicString.cpp (132738 => 132739)


--- trunk/Source/WTF/wtf/text/AtomicString.cpp	2012-10-27 20:31:04 UTC (rev 132738)
+++ trunk/Source/WTF/wtf/text/AtomicString.cpp	2012-10-27 20:33:17 UTC (rev 132739)
@@ -135,7 +135,7 @@
 
     static void translate(StringImpl*& location, const UCharBuffer& buf, unsigned hash)
     {
-        location = StringImpl::create(buf.s, buf.length).leakRef();
+        location = StringImpl::create8BitIfPossible(buf.s, buf.length).leakRef();
         location->setHash(hash);
         location->setIsAtomic(true);
     }

Modified: trunk/Source/WTF/wtf/text/StringImpl.cpp (132738 => 132739)


--- trunk/Source/WTF/wtf/text/StringImpl.cpp	2012-10-27 20:31:04 UTC (rev 132738)
+++ trunk/Source/WTF/wtf/text/StringImpl.cpp	2012-10-27 20:33:17 UTC (rev 132739)
@@ -261,6 +261,23 @@
     return string.release();
 }
 
+PassRefPtr<StringImpl> StringImpl::create8BitIfPossible(const UChar* characters, unsigned length)
+{
+    if (!characters || !length)
+        return empty();
+
+    LChar* data;
+    RefPtr<StringImpl> string = createUninitialized(length, data);
+
+    for (size_t i = 0; i < length; ++i) {
+        if (characters[i] & 0xff00)
+            return create(characters, length);
+        data[i] = static_cast<LChar>(characters[i]);
+    }
+
+    return string.release();
+}
+
 PassRefPtr<StringImpl> StringImpl::create(const LChar* string)
 {
     if (!string)

Modified: trunk/Source/WTF/wtf/text/StringImpl.h (132738 => 132739)


--- trunk/Source/WTF/wtf/text/StringImpl.h	2012-10-27 20:31:04 UTC (rev 132738)
+++ trunk/Source/WTF/wtf/text/StringImpl.h	2012-10-27 20:33:17 UTC (rev 132739)
@@ -352,6 +352,7 @@
 
     WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> create(const UChar*, unsigned length);
     WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> create(const LChar*, unsigned length);
+    WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> create8BitIfPossible(const UChar*, unsigned length);
     ALWAYS_INLINE static PassRefPtr<StringImpl> create(const char* s, unsigned length) { return create(reinterpret_cast<const LChar*>(s), length); }
     WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> create(const LChar*);
     ALWAYS_INLINE static PassRefPtr<StringImpl> create(const char* s) { return create(reinterpret_cast<const LChar*>(s)); }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to