Title: [163341] trunk/Source/WTF
Revision
163341
Author
ander...@apple.com
Date
2014-02-03 16:37:15 -0800 (Mon, 03 Feb 2014)

Log Message

More tail pointer consolidation
https://bugs.webkit.org/show_bug.cgi?id=128139

Reviewed by Andreas Kling.

Add a new tailOffset() function and reimplement allocationSize() and tailPointer()
in terms of it. Use tailPointer() instead of reinterpret_cast-ing this + 1.

* wtf/text/StringImpl.cpp:
(WTF::StringImpl::createUninitializedInternalNonEmpty):
* wtf/text/StringImpl.h:
(WTF::StringImpl::StringImpl):
(WTF::StringImpl::requiresCopy):
(WTF::StringImpl::allocationSize):
(WTF::StringImpl::tailOffset):
(WTF::StringImpl::tailPointer):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (163340 => 163341)


--- trunk/Source/WTF/ChangeLog	2014-02-04 00:29:22 UTC (rev 163340)
+++ trunk/Source/WTF/ChangeLog	2014-02-04 00:37:15 UTC (rev 163341)
@@ -1,3 +1,22 @@
+2014-02-03  Anders Carlsson  <ander...@apple.com>
+
+        More tail pointer consolidation
+        https://bugs.webkit.org/show_bug.cgi?id=128139
+
+        Reviewed by Andreas Kling.
+
+        Add a new tailOffset() function and reimplement allocationSize() and tailPointer()
+        in terms of it. Use tailPointer() instead of reinterpret_cast-ing this + 1.
+
+        * wtf/text/StringImpl.cpp:
+        (WTF::StringImpl::createUninitializedInternalNonEmpty):
+        * wtf/text/StringImpl.h:
+        (WTF::StringImpl::StringImpl):
+        (WTF::StringImpl::requiresCopy):
+        (WTF::StringImpl::allocationSize):
+        (WTF::StringImpl::tailOffset):
+        (WTF::StringImpl::tailPointer):
+
 2014-02-03  Gustavo Noronha Silva  <g...@gnome.org>
 
         [GTK][CMake] Enable SUBPIXEL_LAYOUT in FeatureDefines.h like EFL does

Modified: trunk/Source/WTF/wtf/text/StringImpl.cpp (163340 => 163341)


--- trunk/Source/WTF/wtf/text/StringImpl.cpp	2014-02-04 00:29:22 UTC (rev 163340)
+++ trunk/Source/WTF/wtf/text/StringImpl.cpp	2014-02-04 00:37:15 UTC (rev 163341)
@@ -197,7 +197,7 @@
         CRASH();
     StringImpl* string = static_cast<StringImpl*>(fastMalloc(allocationSize<CharType>(length)));
 
-    data = "" + 1);
+    data = ""
     return constructInternal<CharType>(string, length);
 }
 

Modified: trunk/Source/WTF/wtf/text/StringImpl.h (163340 => 163341)


--- trunk/Source/WTF/wtf/text/StringImpl.h	2014-02-04 00:29:22 UTC (rev 163340)
+++ trunk/Source/WTF/wtf/text/StringImpl.h	2014-02-04 00:37:15 UTC (rev 163341)
@@ -197,7 +197,7 @@
     StringImpl(unsigned length, Force8Bit)
         : m_refCount(s_refCountIncrement)
         , m_length(length)
-        , m_data8(reinterpret_cast<const LChar*>(this + 1))
+        , m_data8(tailPointer<LChar>())
         , m_buffer(0)
         , m_hashAndFlags(s_hashFlag8BitBuffer | BufferInternal)
     {
@@ -211,7 +211,7 @@
     StringImpl(unsigned length)
         : m_refCount(s_refCountIncrement)
         , m_length(length)
-        , m_data16(reinterpret_cast<const UChar*>(this + 1))
+        , m_data16(tailPointer<UChar>())
         , m_buffer(0)
         , m_hashAndFlags(BufferInternal)
     {
@@ -765,20 +765,32 @@
             return true;
 
         if (is8Bit())
-            return reinterpret_cast<const void*>(m_data8) == reinterpret_cast<const void*>(this + 1);
-        return reinterpret_cast<const void*>(m_data16) == reinterpret_cast<const void*>(this + 1);
+            return m_data8 == tailPointer<LChar>();
+        return m_data16 == tailPointer<UChar>();
     }
 
     template<typename T>
     static size_t allocationSize(unsigned tailElementCount)
     {
-        return sizeof(StringImpl) + tailElementCount * sizeof(T);
+        return tailOffset<T>() + tailElementCount * sizeof(T);
     }
 
     template<typename T>
+    static ptrdiff_t tailOffset()
+    {
+        return roundUpToMultipleOf<alignof(T)>(sizeof(StringImpl));
+    }
+
+    template<typename T>
+    const T* tailPointer() const
+    {
+        return reinterpret_cast<const T*>(reinterpret_cast<const uint8_t*>(this) + tailOffset<T>());
+    }
+
+    template<typename T>
     T* tailPointer()
     {
-        return reinterpret_cast<T*>(this + 1);
+        return reinterpret_cast<T*>(reinterpret_cast<uint8_t*>(this) + tailOffset<T>());
     }
 
     // This number must be at least 2 to avoid sharing empty, null as well as 1 character strings from SmallStrings.
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to