Modified: trunk/Source/WTF/wtf/text/StringImpl.cpp (152361 => 152362)
--- trunk/Source/WTF/wtf/text/StringImpl.cpp 2013-07-03 17:03:53 UTC (rev 152361)
+++ trunk/Source/WTF/wtf/text/StringImpl.cpp 2013-07-03 17:05:30 UTC (rev 152362)
@@ -182,21 +182,8 @@
return adoptRef(new StringImpl(characters, length, ConstructWithoutCopying));
}
-template <typename CharType>
-inline PassRefPtr<StringImpl> StringImpl::constructInternal(StringImpl* stringImpl, unsigned length)
+PassRefPtr<StringImpl> StringImpl::createUninitialized(unsigned length, LChar*& data)
{
- return adoptRef(new (NotNull, stringImpl) StringImpl(length));
-}
-
-template <>
-inline PassRefPtr<StringImpl> StringImpl::constructInternal<LChar>(StringImpl* stringImpl, unsigned length)
-{
- return adoptRef(new (NotNull, stringImpl) StringImpl(length, Force8BitConstructor));
-}
-
-template <typename CharType>
-inline PassRefPtr<StringImpl> StringImpl::createUninitializedInternal(unsigned length, CharType*& data)
-{
if (!length) {
data = ""
return empty();
@@ -205,27 +192,35 @@
// Allocate a single buffer large enough to contain the StringImpl
// struct as well as the data which it contains. This removes one
// heap allocation from this call.
- if (length > ((std::numeric_limits<unsigned>::max() - sizeof(StringImpl)) / sizeof(CharType)))
+ if (length > ((std::numeric_limits<unsigned>::max() - sizeof(StringImpl)) / sizeof(LChar)))
CRASH();
- size_t size = sizeof(StringImpl) + length * sizeof(CharType);
+ size_t size = sizeof(StringImpl) + length * sizeof(LChar);
StringImpl* string = static_cast<StringImpl*>(fastMalloc(size));
- data = "" + 1);
- return constructInternal<CharType>(string, length);
+ data = "" + 1);
+ return adoptRef(new (NotNull, string) StringImpl(length, Force8BitConstructor));
}
-PassRefPtr<StringImpl> StringImpl::createUninitialized(unsigned length, LChar*& data)
+PassRefPtr<StringImpl> StringImpl::createUninitialized(unsigned length, UChar*& data)
{
- return createUninitializedInternal(length, data);
-}
+ if (!length) {
+ data = ""
+ return empty();
+ }
-PassRefPtr<StringImpl> StringImpl::createUninitialized(unsigned length, UChar*& data)
-{
- return createUninitializedInternal(length, data);
+ // Allocate a single buffer large enough to contain the StringImpl
+ // struct as well as the data which it contains. This removes one
+ // heap allocation from this call.
+ if (length > ((std::numeric_limits<unsigned>::max() - sizeof(StringImpl)) / sizeof(UChar)))
+ CRASH();
+ size_t size = sizeof(StringImpl) + length * sizeof(UChar);
+ StringImpl* string = static_cast<StringImpl*>(fastMalloc(size));
+
+ data = "" + 1);
+ return adoptRef(new (NotNull, string) StringImpl(length));
}
-template <typename CharType>
-inline PassRefPtr<StringImpl> StringImpl::reallocateInternal(PassRefPtr<StringImpl> originalString, unsigned length, CharType*& data)
+PassRefPtr<StringImpl> StringImpl::reallocate(PassRefPtr<StringImpl> originalString, unsigned length, LChar*& data)
{
ASSERT(originalString->is8Bit());
ASSERT(originalString->hasOneRef());
@@ -237,46 +232,58 @@
}
// Same as createUninitialized() except here we use fastRealloc.
- if (length > ((std::numeric_limits<unsigned>::max() - sizeof(StringImpl)) / sizeof(CharType)))
+ if (length > ((std::numeric_limits<unsigned>::max() - sizeof(StringImpl)) / sizeof(LChar)))
CRASH();
- size_t size = sizeof(StringImpl) + length * sizeof(CharType);
+ size_t size = sizeof(StringImpl) + length * sizeof(LChar);
originalString->~StringImpl();
StringImpl* string = static_cast<StringImpl*>(fastRealloc(originalString.leakRef(), size));
- data = "" + 1);
- return constructInternal<CharType>(string, length);
+ data = "" + 1);
+ return adoptRef(new (NotNull, string) StringImpl(length, Force8BitConstructor));
}
-PassRefPtr<StringImpl> StringImpl::reallocate(PassRefPtr<StringImpl> originalString, unsigned length, LChar*& data)
+PassRefPtr<StringImpl> StringImpl::reallocate(PassRefPtr<StringImpl> originalString, unsigned length, UChar*& data)
{
- return reallocateInternal(originalString, length, data);
-}
+ ASSERT(!originalString->is8Bit());
+ ASSERT(originalString->hasOneRef());
+ ASSERT(originalString->bufferOwnership() == BufferInternal);
-PassRefPtr<StringImpl> StringImpl::reallocate(PassRefPtr<StringImpl> originalString, unsigned length, UChar*& data)
-{
- return reallocateInternal(originalString, length, data);
+ if (!length) {
+ data = ""
+ return empty();
+ }
+
+ // Same as createUninitialized() except here we use fastRealloc.
+ if (length > ((std::numeric_limits<unsigned>::max() - sizeof(StringImpl)) / sizeof(UChar)))
+ CRASH();
+ size_t size = sizeof(StringImpl) + length * sizeof(UChar);
+ originalString->~StringImpl();
+ StringImpl* string = static_cast<StringImpl*>(fastRealloc(originalString.leakRef(), size));
+
+ data = "" + 1);
+ return adoptRef(new (NotNull, string) StringImpl(length));
}
-template <typename CharType>
-inline PassRefPtr<StringImpl> StringImpl::createInternal(const CharType* characters, unsigned length)
+PassRefPtr<StringImpl> StringImpl::create(const UChar* characters, unsigned length)
{
if (!characters || !length)
return empty();
- CharType* data;
+ UChar* data;
RefPtr<StringImpl> string = createUninitialized(length, data);
- memcpy(data, characters, length * sizeof(CharType));
+ memcpy(data, characters, length * sizeof(UChar));
return string.release();
}
-PassRefPtr<StringImpl> StringImpl::create(const UChar* characters, unsigned length)
+PassRefPtr<StringImpl> StringImpl::create(const LChar* characters, unsigned length)
{
- return createInternal(characters, length);
-}
+ if (!characters || !length)
+ return empty();
-PassRefPtr<StringImpl> StringImpl::create(const LChar* characters, unsigned length)
-{
- return createInternal(characters, length);
+ LChar* data;
+ RefPtr<StringImpl> string = createUninitialized(length, data);
+ memcpy(data, characters, length * sizeof(LChar));
+ return string.release();
}
PassRefPtr<StringImpl> StringImpl::create8BitIfPossible(const UChar* characters, unsigned length)
Modified: trunk/Source/WTF/wtf/text/StringImpl.h (152361 => 152362)
--- trunk/Source/WTF/wtf/text/StringImpl.h 2013-07-03 17:03:53 UTC (rev 152361)
+++ trunk/Source/WTF/wtf/text/StringImpl.h 2013-07-03 17:05:30 UTC (rev 152362)
@@ -770,10 +770,6 @@
bool isStatic() const { return m_refCount & s_refCountFlagIsStaticString; }
template <class UCharPredicate> PassRefPtr<StringImpl> stripMatchedCharacters(UCharPredicate);
template <typename CharType, class UCharPredicate> PassRefPtr<StringImpl> simplifyMatchedCharactersToSpace(UCharPredicate);
- template <typename CharType> static PassRefPtr<StringImpl> constructInternal(StringImpl*, unsigned);
- template <typename CharType> static PassRefPtr<StringImpl> createUninitializedInternal(unsigned, CharType*&);
- template <typename CharType> static PassRefPtr<StringImpl> reallocateInternal(PassRefPtr<StringImpl>, unsigned, CharType*&);
- template <typename CharType> static PassRefPtr<StringImpl> createInternal(const CharType*, unsigned);
WTF_EXPORT_STRING_API NEVER_INLINE const UChar* getData16SlowCase() const;
WTF_EXPORT_PRIVATE NEVER_INLINE unsigned hashSlowCase() const;