Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1095)

Unified Diff: third_party/WebKit/Source/wtf/text/StringStatics.cpp

Issue 1405573003: Introduce StringImpl::createPreallocatedStatic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: +comment. Removed StringImpl::createStatic. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringImpl.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
}
}
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringImpl.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698