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

Unified Diff: third_party/WebKit/Source/wtf/text/StringImpl.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
Index: third_party/WebKit/Source/wtf/text/StringImpl.cpp
diff --git a/third_party/WebKit/Source/wtf/text/StringImpl.cpp b/third_party/WebKit/Source/wtf/text/StringImpl.cpp
index 56b81dabfe350d8e03258d5204c07c00f4dc51b7..bc5ad1352a8c736a567fe704e35f23134806a07d 100644
--- a/third_party/WebKit/Source/wtf/text/StringImpl.cpp
+++ b/third_party/WebKit/Source/wtf/text/StringImpl.cpp
@@ -341,32 +341,24 @@ void StringImpl::freezeStaticStrings()
#endif
}
+
unsigned StringImpl::m_highestStaticStringLength = 0;
-StringImpl* StringImpl::createStatic(const char* string, unsigned length, unsigned hash)
+StringImpl* StringImpl::createPreallocatedStatic(void* buffer, unsigned length, unsigned hash)
{
ASSERT(s_allowCreationOfStaticStrings);
- ASSERT(string);
+ ASSERT(buffer);
ASSERT(length);
+ StringImpl* impl = static_cast<StringImpl*>(buffer);
+
StaticStringsTable::const_iterator it = staticStrings().find(hash);
if (it != staticStrings().end()) {
- ASSERT(!memcmp(string, it->value + 1, length * sizeof(LChar)));
+ ASSERT(!memcmp(reinterpret_cast<LChar*>(impl + 1), it->value + 1, length * sizeof(LChar)));
return it->value;
}
- // 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.
- RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof(StringImpl)) / sizeof(LChar)));
- size_t size = sizeof(StringImpl) + length * sizeof(LChar);
-
- WTF_ANNOTATE_SCOPED_MEMORY_LEAK;
- StringImpl* impl = static_cast<StringImpl*>(Partitions::bufferMalloc(size));
-
- LChar* data = reinterpret_cast<LChar*>(impl + 1);
impl = new (impl) StringImpl(length, hash, StaticString);
- memcpy(data, string, length * sizeof(LChar));
#if ENABLE(ASSERT)
impl->assertHashIsCorrect();
#endif
@@ -375,7 +367,7 @@ StringImpl* StringImpl::createStatic(const char* string, unsigned length, unsign
m_highestStaticStringLength = std::max(m_highestStaticStringLength, length);
staticStrings().add(hash, impl);
WTF_ANNOTATE_BENIGN_RACE(impl,
- "Benign race on the reference counter of a static string created by StringImpl::createStatic");
+ "Benign race on the reference counter of a static string created by StringImpl::createPreallocatedStatic");
return impl;
}
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringImpl.h ('k') | third_party/WebKit/Source/wtf/text/StringStatics.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698