Commit 0f79b586 authored by jorlow@chromium.org's avatar jorlow@chromium.org
Browse files

2009-10-07 Jens Alfke <snej@chromium.org>

        Reviewed by Dave Levin.

        Fix StringImpl::m_buffer
        https://bugs.webkit.org/show_bug.cgi?id=30189

        Fix my previous StringImpl patch to avoid using an indefinite-length array member,
        since MSVC doesn't like it. Instead, go back to offsetting by sizeof(StringImpl).

        * platform/text/StringImpl.cpp:
        (WebCore::StringImpl::StringImpl):
        (WebCore::StringImpl::createUninitialized):
        * platform/text/StringImpl.h:
        (WebCore::StringImpl::bufferIsInternal):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@49279 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0ad18647
2009-10-07 Jens Alfke <snej@chromium.org>
Reviewed by Dave Levin.
Fix StringImpl::m_buffer
https://bugs.webkit.org/show_bug.cgi?id=30189
Fix my previous StringImpl patch to avoid using an indefinite-length array member,
since MSVC doesn't like it. Instead, go back to offsetting by sizeof(StringImpl).
* platform/text/StringImpl.cpp:
(WebCore::StringImpl::StringImpl):
(WebCore::StringImpl::createUninitialized):
* platform/text/StringImpl.h:
(WebCore::StringImpl::bufferIsInternal):
2009-10-07 Aaron Boodman <aa@chromium.org>
 
Reviewed by Adam Barth.
......@@ -36,7 +36,6 @@
#include "ThreadGlobalData.h"
#include <wtf/dtoa.h>
#include <wtf/Assertions.h>
#include <wtf/StdLibExtras.h>
#include <wtf/Threading.h>
#include <wtf/unicode/Unicode.h>
......@@ -83,7 +82,6 @@ StringImpl::StringImpl()
: m_data(0)
, m_length(0)
, m_hash(0)
, m_buffer()
{
// Ensure that the hash is computed so that AtomicStringHash can call existingHash()
// with impunity. The empty string is special because it is never entered into
......@@ -95,7 +93,6 @@ inline StringImpl::StringImpl(UChar* characters, unsigned length, AdoptBuffer)
: m_data(characters)
, m_length(length)
, m_hash(0)
, m_buffer()
{
ASSERT(characters);
ASSERT(length);
......@@ -106,7 +103,6 @@ StringImpl::StringImpl(const UChar* characters, unsigned length, unsigned hash)
: m_data(0)
, m_length(length)
, m_hash(hash)
, m_buffer()
{
ASSERT(hash);
ASSERT(characters);
......@@ -123,7 +119,6 @@ StringImpl::StringImpl(const char* characters, unsigned length, unsigned hash)
: m_data(0)
, m_length(length)
, m_hash(hash)
, m_buffer()
{
ASSERT(hash);
ASSERT(characters);
......@@ -959,9 +954,9 @@ PassRefPtr<StringImpl> StringImpl::createUninitialized(unsigned length, UChar*&
// 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.
size_t size = OBJECT_OFFSETOF(StringImpl, m_buffer) + length * sizeof(UChar);
size_t size = sizeof(StringImpl) + length * sizeof(UChar);
StringImpl* string = static_cast<StringImpl*>(fastMalloc(size));
data = const_cast<UChar*>(&string->m_buffer[0]);
data = reinterpret_cast<UChar*>(string + 1);
string = new (string) StringImpl(data, length, AdoptBuffer());
return adoptRef(string);
}
......
......@@ -191,7 +191,7 @@ private:
// The StringImpl struct and its data may be allocated within a single heap block.
// In this case, the m_data pointer is an "internal buffer", and does not need to be deallocated.
bool bufferIsInternal() { return m_data == &m_buffer[0]; }
bool bufferIsInternal() { return m_data == reinterpret_cast<const UChar*>(this + 1); }
enum StringImplFlags {
HasTerminatingNullCharacter,
......@@ -202,17 +202,8 @@ private:
unsigned m_length;
mutable unsigned m_hash;
PtrAndFlags<SharedUChar, StringImplFlags> m_sharedBufferAndFlags;
// m_buffer is declared with no size; the compiler treats it as zero size,
// and the actual size is determined when the instance is created.
// It will be zero unless using an "internal buffer", in which case m_data
// will point to m_buffer and the length of m_buffer will be equal to m_length.
#if COMPILER(GCC)
const UChar m_buffer[];
#else
// Non-GCC compilers may not accept the "[]" syntax. So we'll waste 2 bytes when
// allocating non-internal strings.
const UChar m_buffer[1];
#endif
// There is a fictitious variable-length UChar array at the end, which is used
// as the internal buffer by the createUninitialized and create methods.
};
bool equal(StringImpl*, StringImpl*);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment