Title: [163326] trunk/Source/WTF
- Revision
- 163326
- Author
- ander...@apple.com
- Date
- 2014-02-03 14:04:56 -0800 (Mon, 03 Feb 2014)
Log Message
Consolidate StringImpl tail handling into two functions
https://bugs.webkit.org/show_bug.cgi?id=128122
Reviewed by Andreas Kling.
* wtf/text/StringImpl.cpp:
(WTF::StringImpl::createUninitializedInternalNonEmpty):
(WTF::StringImpl::reallocateInternal):
* wtf/text/StringImpl.h:
(WTF::StringImpl::tryCreateUninitialized):
(WTF::StringImpl::allocationSize):
(WTF::StringImpl::tailPointer):
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (163325 => 163326)
--- trunk/Source/WTF/ChangeLog 2014-02-03 21:52:55 UTC (rev 163325)
+++ trunk/Source/WTF/ChangeLog 2014-02-03 22:04:56 UTC (rev 163326)
@@ -1,3 +1,18 @@
+2014-02-03 Anders Carlsson <ander...@apple.com>
+
+ Consolidate StringImpl tail handling into two functions
+ https://bugs.webkit.org/show_bug.cgi?id=128122
+
+ Reviewed by Andreas Kling.
+
+ * wtf/text/StringImpl.cpp:
+ (WTF::StringImpl::createUninitializedInternalNonEmpty):
+ (WTF::StringImpl::reallocateInternal):
+ * wtf/text/StringImpl.h:
+ (WTF::StringImpl::tryCreateUninitialized):
+ (WTF::StringImpl::allocationSize):
+ (WTF::StringImpl::tailPointer):
+
2014-02-03 Darin Adler <da...@apple.com>
Remove Unicode.h
Modified: trunk/Source/WTF/wtf/text/StringImpl.cpp (163325 => 163326)
--- trunk/Source/WTF/wtf/text/StringImpl.cpp 2014-02-03 21:52:55 UTC (rev 163325)
+++ trunk/Source/WTF/wtf/text/StringImpl.cpp 2014-02-03 22:04:56 UTC (rev 163326)
@@ -195,8 +195,7 @@
// heap allocation from this call.
if (length > ((std::numeric_limits<unsigned>::max() - sizeof(StringImpl)) / sizeof(CharType)))
CRASH();
- size_t size = sizeof(StringImpl) + length * sizeof(CharType);
- StringImpl* string = static_cast<StringImpl*>(fastMalloc(size));
+ StringImpl* string = static_cast<StringImpl*>(fastMalloc(allocationSize<CharType>(length)));
data = "" + 1);
return constructInternal<CharType>(string, length);
@@ -226,11 +225,11 @@
// Same as createUninitialized() except here we use fastRealloc.
if (length > ((std::numeric_limits<unsigned>::max() - sizeof(StringImpl)) / sizeof(CharType)))
CRASH();
- size_t size = sizeof(StringImpl) + length * sizeof(CharType);
+
originalString->~StringImpl();
- StringImpl* string = static_cast<StringImpl*>(fastRealloc(originalString.leakRef(), size));
+ StringImpl* string = static_cast<StringImpl*>(fastRealloc(originalString.leakRef(), allocationSize<CharType>(length)));
- data = "" + 1);
+ data = ""
return constructInternal<CharType>(string, length);
}
Modified: trunk/Source/WTF/wtf/text/StringImpl.h (163325 => 163326)
--- trunk/Source/WTF/wtf/text/StringImpl.h 2014-02-03 21:52:55 UTC (rev 163325)
+++ trunk/Source/WTF/wtf/text/StringImpl.h 2014-02-03 22:04:56 UTC (rev 163326)
@@ -408,11 +408,11 @@
return 0;
}
StringImpl* resultImpl;
- if (!tryFastMalloc(sizeof(T) * length + sizeof(StringImpl)).getValue(resultImpl)) {
+ if (!tryFastMalloc(allocationSize<T>(length)).getValue(resultImpl)) {
output = 0;
return 0;
}
- output = reinterpret_cast<T*>(resultImpl + 1);
+ output = resultImpl->tailPointer<T>();
return constructInternal<T>(resultImpl, length);
}
@@ -769,6 +769,18 @@
return reinterpret_cast<const void*>(m_data16) == reinterpret_cast<const void*>(this + 1);
}
+ template<typename T>
+ static size_t allocationSize(unsigned tailElementCount)
+ {
+ return sizeof(StringImpl) + tailElementCount * sizeof(T);
+ }
+
+ template<typename T>
+ T* tailPointer()
+ {
+ return reinterpret_cast<T*>(this + 1);
+ }
+
// This number must be at least 2 to avoid sharing empty, null as well as 1 character strings from SmallStrings.
static const unsigned s_copyCharsInlineCutOff = 20;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes