| Index: Source/wtf/text/StringImpl.cpp
|
| diff --git a/Source/wtf/text/StringImpl.cpp b/Source/wtf/text/StringImpl.cpp
|
| index dfaef64356afd78cdbeef85436b84286d5243fac..7373712e42fac790665683f4023768344c763650 100644
|
| --- a/Source/wtf/text/StringImpl.cpp
|
| +++ b/Source/wtf/text/StringImpl.cpp
|
| @@ -25,6 +25,7 @@
|
| #include "config.h"
|
| #include "wtf/text/StringImpl.h"
|
|
|
| +#include "wtf/DefaultAllocator.h"
|
| #include "wtf/DynamicAnnotations.h"
|
| #include "wtf/LeakAnnotations.h"
|
| #include "wtf/MainThread.h"
|
| @@ -266,7 +267,11 @@ void* StringImpl::operator new(size_t size)
|
|
|
| void StringImpl::operator delete(void* ptr)
|
| {
|
| - Partitions::bufferFree(ptr);
|
| + if (static_cast<StringImpl*>(ptr)->isBuffered()) {
|
| + DefaultAllocator::freeBufferStringBacking(ptr);
|
| + } else {
|
| + DefaultAllocator::freeBufferStringBacking(ptr);
|
| + }
|
| }
|
|
|
| inline StringImpl::~StringImpl()
|
| @@ -308,6 +313,9 @@ PassRefPtr<StringImpl> StringImpl::createUninitialized(unsigned length, UChar*&
|
| return empty();
|
| }
|
|
|
| +#if BUFFER_ALLOCATOR_DEBUG
|
| + fprintf(stderr, "StringImpl::create: size=%u\n", length);
|
| +#endif
|
| // 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.
|
| @@ -317,7 +325,45 @@ PassRefPtr<StringImpl> StringImpl::createUninitialized(unsigned length, UChar*&
|
| return adoptRef(new (string) StringImpl(length));
|
| }
|
|
|
| -PassRefPtr<StringImpl> StringImpl::reallocate(PassRefPtr<StringImpl> originalString, unsigned length)
|
| +PassRefPtr<StringImpl> StringImpl::createBufferUninitialized(unsigned length, LChar*& data, void* holder)
|
| +{
|
| + if (!length) {
|
| + data = 0;
|
| + return empty();
|
| + }
|
| +
|
| +#if BUFFER_ALLOCATOR_DEBUG
|
| + fprintf(stderr, "StringImpl::create: size=%u\n", length);
|
| +#endif
|
| + // 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.
|
| + StringImpl* string = static_cast<StringImpl*>(DefaultAllocator::allocateBufferStringBacking(allocationSize<LChar>(length), holder));
|
| +
|
| + data = reinterpret_cast<LChar*>(string + 1);
|
| + return adoptRef(new (string) StringImpl(length, Force8BitConstructor, true));
|
| +}
|
| +
|
| +PassRefPtr<StringImpl> StringImpl::createBufferUninitialized(unsigned length, UChar*& data, void* holder)
|
| +{
|
| + if (!length) {
|
| + data = 0;
|
| + return empty();
|
| + }
|
| +
|
| +#if BUFFER_ALLOCATOR_DEBUG
|
| + fprintf(stderr, "StringImpl::create: size=%u\n", length);
|
| +#endif
|
| + // 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.
|
| + StringImpl* string = static_cast<StringImpl*>(DefaultAllocator::allocateBufferStringBacking(allocationSize<UChar>(length), holder));
|
| +
|
| + data = reinterpret_cast<UChar*>(string + 1);
|
| + return adoptRef(new (string) StringImpl(length, true));
|
| +}
|
| +
|
| +PassRefPtr<StringImpl> StringImpl::reallocate(PassRefPtr<StringImpl> originalString, unsigned length, void* holder)
|
| {
|
| ASSERT(originalString->hasOneRef());
|
|
|
| @@ -327,11 +373,50 @@ PassRefPtr<StringImpl> StringImpl::reallocate(PassRefPtr<StringImpl> originalStr
|
| bool is8Bit = originalString->is8Bit();
|
| // Same as createUninitialized() except here we use realloc.
|
| size_t size = is8Bit ? allocationSize<LChar>(length) : allocationSize<UChar>(length);
|
| +
|
| + size_t originalSize = originalString->is8Bit() ? allocationSize<LChar>(originalString->length()) : allocationSize<UChar>(originalString->length());
|
| + if (originalSize == size)
|
| + return originalString;
|
| +
|
| + if (originalString->isBuffered()) {
|
| + if (originalSize < size) {
|
| + if (DefaultAllocator::expandBufferStringBacking(originalString.get(), size)) {
|
| +#if BUFFER_ALLOCATOR_DEBUG
|
| + fprintf(stderr, "StringImpl::expand succeeded: originalSize=%ld, size=%ld\n", originalSize, size);
|
| +#endif
|
| + originalString->setLength(length);
|
| + return originalString;
|
| + }
|
| +#if BUFFER_ALLOCATOR_DEBUG
|
| + fprintf(stderr, "StringImpl::expand failed: originalSize=%ld, size=%ld\n", originalSize, size);
|
| +#endif
|
| + } else if (originalSize > size) {
|
| + if (DefaultAllocator::shrinkBufferStringBacking(originalString.get(), originalSize, size)) {
|
| +#if BUFFER_ALLOCATOR_DEBUG
|
| + fprintf(stderr, "StringImpl::shrink succeeded: originalSize=%ld, size=%ld\n", originalSize, size);
|
| +#endif
|
| + originalString->setLength(length);
|
| + return originalString;
|
| + }
|
| +#if BUFFER_ALLOCATOR_DEBUG
|
| + fprintf(stderr, "StringImpl::shrink failed: originalSize=%ld, size=%ld\n", originalSize, size);
|
| +#endif
|
| + }
|
| + } else {
|
| +#if BUFFER_ALLOCATOR_DEBUG
|
| + fprintf(stderr, "StringImpl::reallocate failed: !isBuffered originalSize=%ld, size=%ld\n", originalSize, size);
|
| +#endif
|
| + }
|
| +
|
| + StringImpl* string = static_cast<StringImpl*>(DefaultAllocator::allocateBufferStringBacking(size, holder));
|
| + size_t copySize = originalSize;
|
| + if (copySize > size)
|
| + copySize = size;
|
| + memcpy(string, originalString.get(), copySize);
|
| originalString->~StringImpl();
|
| - StringImpl* string = static_cast<StringImpl*>(Partitions::bufferRealloc(originalString.leakRef(), size));
|
| if (is8Bit)
|
| - return adoptRef(new (string) StringImpl(length, Force8BitConstructor));
|
| - return adoptRef(new (string) StringImpl(length));
|
| + return adoptRef(new (string) StringImpl(length, Force8BitConstructor, true));
|
| + return adoptRef(new (string) StringImpl(length, true));
|
| }
|
|
|
| static StaticStringsTable& staticStrings()
|
|
|