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

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: 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 303ee9d1ddd1707c356393bd1b2eabdde4c4fce9..9591ba9a05404eae927f140c22f2482dfb14a4af 100644
--- a/third_party/WebKit/Source/wtf/text/StringImpl.cpp
+++ b/third_party/WebKit/Source/wtf/text/StringImpl.cpp
@@ -343,6 +343,34 @@ void StringImpl::freezeStaticStrings()
unsigned StringImpl::m_highestStaticStringLength = 0;
+StringImpl* StringImpl::createPreallocatedStatic(void* buffer, unsigned length, unsigned hash)
+{
+ ASSERT(s_allowCreationOfStaticStrings);
+ ASSERT(buffer);
+ ASSERT(length);
+
+ StringImpl* impl = static_cast<StringImpl*>(buffer);
+
+ StaticStringsTable::const_iterator it = staticStrings().find(hash);
+ if (it != staticStrings().end()) {
+ ASSERT(!memcmp(reinterpret_cast<LChar*>(impl + 1), it->value + 1, length * sizeof(LChar)));
+ return it->value;
kouhei (in TOK) 2015/10/21 01:08:17 Are we ever going to reach here? If not, ASSERT?
tzik 2015/10/28 14:33:31 We do actually reach here due to duplicated static
+ }
+
+ impl = new (impl) StringImpl(length, hash, StaticString);
+#if ENABLE(ASSERT)
+ impl->assertHashIsCorrect();
+#endif
+
+ ASSERT(isMainThread());
+ 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");
tkent 2015/10/21 03:19:34 createStatic -> createPreallocatedStatic?
tzik 2015/10/28 14:33:31 Done.
+
+ return impl;
+}
+
StringImpl* StringImpl::createStatic(const char* string, unsigned length, unsigned hash)
{
ASSERT(s_allowCreationOfStaticStrings);

Powered by Google App Engine
This is Rietveld 408576698