Title: [98993] trunk/Source/_javascript_Core
Revision
98993
Author
[email protected]
Date
2011-11-01 12:52:29 -0700 (Tue, 01 Nov 2011)

Log Message

StringImpl::reallocate() should have a 8-bit version
https://bugs.webkit.org/show_bug.cgi?id=71210

Patch by Xianzhu Wang <[email protected]> on 2011-11-01
Reviewed by Geoffrey Garen.

* wtf/text/StringImpl.cpp:
(WTF::StringImpl::reallocate):
* wtf/text/StringImpl.h:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (98992 => 98993)


--- trunk/Source/_javascript_Core/ChangeLog	2011-11-01 19:28:52 UTC (rev 98992)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-11-01 19:52:29 UTC (rev 98993)
@@ -1,3 +1,14 @@
+2011-11-01  Xianzhu Wang  <[email protected]>
+
+        StringImpl::reallocate() should have a 8-bit version
+        https://bugs.webkit.org/show_bug.cgi?id=71210
+
+        Reviewed by Geoffrey Garen.
+
+        * wtf/text/StringImpl.cpp:
+        (WTF::StringImpl::reallocate):
+        * wtf/text/StringImpl.h:
+
 2011-10-31  Filip Pizlo  <[email protected]>
 
         The GC should be parallel

Modified: trunk/Source/_javascript_Core/wtf/text/StringImpl.cpp (98992 => 98993)


--- trunk/Source/_javascript_Core/wtf/text/StringImpl.cpp	2011-11-01 19:28:52 UTC (rev 98992)
+++ trunk/Source/_javascript_Core/wtf/text/StringImpl.cpp	2011-11-01 19:52:29 UTC (rev 98993)
@@ -37,8 +37,6 @@
 
 using namespace Unicode;
 
-static const unsigned minLengthToShare = 20;
-
 COMPILE_ASSERT(sizeof(StringImpl) == 2 * sizeof(int) + 3 * sizeof(void*), StringImpl_should_stay_small);
 
 StringImpl::~StringImpl()
@@ -113,9 +111,33 @@
     return adoptRef(new (string) StringImpl(length));
 }
 
+PassRefPtr<StringImpl> StringImpl::reallocate(PassRefPtr<StringImpl> originalString, unsigned length, LChar*& data)
+{
+    ASSERT(originalString->is8Bit());
+    ASSERT(originalString->hasOneRef());
+    ASSERT(originalString->bufferOwnership() == BufferInternal);
+
+    if (!length) {
+        data = ""
+        return empty();
+    }
+
+    // Same as createUninitialized() except here we use fastRealloc.
+    if (length > ((std::numeric_limits<unsigned>::max() - sizeof(StringImpl)) / sizeof(LChar)))
+        CRASH();
+    size_t size = sizeof(StringImpl) + length * sizeof(LChar);
+    originalString->~StringImpl();
+    StringImpl* string = static_cast<StringImpl*>(fastRealloc(originalString.leakRef(), size));
+
+    data = "" + 1);
+    return adoptRef(new (string) StringImpl(length));
+}
+
 PassRefPtr<StringImpl> StringImpl::reallocate(PassRefPtr<StringImpl> originalString, unsigned length, UChar*& data)
 {
-    ASSERT(originalString->hasOneRef() && originalString->bufferOwnership() == BufferInternal);
+    ASSERT(!originalString->is8Bit());
+    ASSERT(originalString->hasOneRef());
+    ASSERT(originalString->bufferOwnership() == BufferInternal);
 
     if (!length) {
         data = ""
@@ -1074,7 +1096,7 @@
         ++srcSegmentStart;
     }
     
-    // If we have 0 matches then we don't have to do any more work to do.
+    // If we have 0 matches then we don't have to do any more work.
     if (!matchCount)
         return this;
     

Modified: trunk/Source/_javascript_Core/wtf/text/StringImpl.h (98992 => 98993)


--- trunk/Source/_javascript_Core/wtf/text/StringImpl.h	2011-11-01 19:28:52 UTC (rev 98992)
+++ trunk/Source/_javascript_Core/wtf/text/StringImpl.h	2011-11-01 19:52:29 UTC (rev 98993)
@@ -242,6 +242,7 @@
     // Reallocate the StringImpl. The originalString must be only owned by the PassRefPtr,
     // and the buffer ownership must be BufferInternal. Just like the input pointer of realloc(),
     // the originalString can't be used after this function.
+    static PassRefPtr<StringImpl> reallocate(PassRefPtr<StringImpl> originalString, unsigned length, LChar*& data);
     static PassRefPtr<StringImpl> reallocate(PassRefPtr<StringImpl> originalString, unsigned length, UChar*& data);
 
     static unsigned flagsOffset() { return OBJECT_OFFSETOF(StringImpl, m_hashAndFlags); }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to