| Index: third_party/WebKit/Source/wtf/text/StringStatics.cpp
|
| diff --git a/third_party/WebKit/Source/wtf/text/StringStatics.cpp b/third_party/WebKit/Source/wtf/text/StringStatics.cpp
|
| index 7a807f6aa21917383201f0813aef5c58581958d2..27317556db776550f21882575dd6faef06349968 100644
|
| --- a/third_party/WebKit/Source/wtf/text/StringStatics.cpp
|
| +++ b/third_party/WebKit/Source/wtf/text/StringStatics.cpp
|
| @@ -79,24 +79,44 @@ void AtomicString::init()
|
| new (NotNull, (void*)&emptyAtom) AtomicString("");
|
| }
|
|
|
| +template <unsigned charactersCount>
|
| +struct PreallocatedStringImplStorage {
|
| + // A StringImpl is built at stringImplStorage in-place.
|
| + // |characters| must be placed soon after |stringImplStorage| to match the memory layout requirement of StringImpl.
|
| + char stringImplStorage[sizeof(StringImpl)];
|
| + char characters[charactersCount];
|
| +};
|
| +
|
| template<unsigned charactersCount>
|
| -PassRefPtr<StringImpl> addStaticASCIILiteral(const char (&characters)[charactersCount])
|
| +PassRefPtr<StringImpl> addStaticASCIILiteral(PreallocatedStringImplStorage<charactersCount>& storage)
|
| {
|
| + ASSERT(reinterpret_cast<char*>(reinterpret_cast<StringImpl*>(&storage) + 1) == storage.characters);
|
| unsigned length = charactersCount - 1;
|
| - unsigned hash = StringHasher::computeHashAndMaskTop8Bits(reinterpret_cast<const LChar*>(characters), length);
|
| - return adoptRef(StringImpl::createStatic(characters, length, hash));
|
| + unsigned hash = StringHasher::computeHashAndMaskTop8Bits(reinterpret_cast<const LChar*>(storage.characters), length);
|
| + return adoptRef(StringImpl::createPreallocatedStatic(&storage, length, hash));
|
| }
|
|
|
| void StringStatics::init()
|
| {
|
| ASSERT(isMainThread());
|
|
|
| +#define ALLOCATE_STRING_IMPL_STORAGE_FOR_LITERAL(name, literal) \
|
| + static PreallocatedStringImplStorage<sizeof(literal)> name = {{}, literal}
|
| +
|
| + ALLOCATE_STRING_IMPL_STORAGE_FOR_LITERAL(star, "*");
|
| + ALLOCATE_STRING_IMPL_STORAGE_FOR_LITERAL(xml, "xml");
|
| + ALLOCATE_STRING_IMPL_STORAGE_FOR_LITERAL(xmlns, "xmlns");
|
| + ALLOCATE_STRING_IMPL_STORAGE_FOR_LITERAL(xlink, "xlink");
|
| + ALLOCATE_STRING_IMPL_STORAGE_FOR_LITERAL(xmlnsWithColon, "xmlns:");
|
| +
|
| +#undef ALLOCATE_STRING_IMPL_STORAGE_FOR_LITERAL
|
| +
|
| // FIXME: These should be allocated at compile time.
|
| - new (NotNull, (void*)&starAtom) AtomicString("*", AtomicString::ConstructFromLiteral);
|
| - new (NotNull, (void*)&xmlAtom) AtomicString(addStaticASCIILiteral("xml"));
|
| - new (NotNull, (void*)&xmlnsAtom) AtomicString(addStaticASCIILiteral("xmlns"));
|
| - new (NotNull, (void*)&xlinkAtom) AtomicString(addStaticASCIILiteral("xlink"));
|
| - new (NotNull, (void*)&xmlnsWithColon) String("xmlns:");
|
| + new (NotNull, (void*)&starAtom) AtomicString(addStaticASCIILiteral(star));
|
| + new (NotNull, (void*)&xmlAtom) AtomicString(addStaticASCIILiteral(xml));
|
| + new (NotNull, (void*)&xmlnsAtom) AtomicString(addStaticASCIILiteral(xmlns));
|
| + new (NotNull, (void*)&xlinkAtom) AtomicString(addStaticASCIILiteral(xlink));
|
| + new (NotNull, (void*)&xlinkAtom) AtomicString(addStaticASCIILiteral(xmlnsWithColon));
|
| }
|
|
|
| }
|
|
|