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

Unified Diff: Source/wtf/text/StringImpl.cpp

Issue 110843004: Replaced HTMLIdentifier with an atomized string factory function (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Review fixes Created 7 years 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 | « Source/wtf/text/StringImpl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/text/StringImpl.cpp
diff --git a/Source/wtf/text/StringImpl.cpp b/Source/wtf/text/StringImpl.cpp
index 090f02534446d24aa92ef17a798665a8646efde7..c429e344da11380b47a48c64bd1eae768869a4f9 100644
--- a/Source/wtf/text/StringImpl.cpp
+++ b/Source/wtf/text/StringImpl.cpp
@@ -358,9 +358,9 @@ PassRefPtr<StringImpl> StringImpl::reallocate(PassRefPtr<StringImpl> originalStr
return adoptRef(new (string) StringImpl(length));
}
-static Vector<StringImpl*>& staticStrings()
+static StaticStringsTable& staticStrings()
{
- DEFINE_STATIC_LOCAL(Vector<StringImpl*>, staticStrings, ());
+ DEFINE_STATIC_LOCAL(StaticStringsTable, staticStrings, ());
return staticStrings;
}
@@ -368,7 +368,7 @@ static Vector<StringImpl*>& staticStrings()
static bool s_allowCreationOfStaticStrings = true;
#endif
-const Vector<StringImpl*>& StringImpl::allStaticStrings()
+const StaticStringsTable& StringImpl::allStaticStrings()
{
return staticStrings();
}
@@ -380,21 +380,28 @@ void StringImpl::freezeStaticStrings()
#ifndef NDEBUG
s_allowCreationOfStaticStrings = false;
#endif
-
- staticStrings().shrinkToFit();
}
+unsigned StringImpl::m_highestStaticStringLength = 0;
+
StringImpl* StringImpl::createStatic(const char* string, unsigned length, unsigned hash)
{
ASSERT(s_allowCreationOfStaticStrings);
ASSERT(string);
ASSERT(length);
+ StaticStringsTable::const_iterator it = staticStrings().find(hash);
+ if (it != staticStrings().end()) {
+ ASSERT(!memcmp(string, 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*>(partitionAllocGeneric(Partitions::getBufferPartition(), size));
@@ -406,7 +413,8 @@ StringImpl* StringImpl::createStatic(const char* string, unsigned length, unsign
#endif
ASSERT(isMainThread());
- staticStrings().append(impl);
+ 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");
« no previous file with comments | « Source/wtf/text/StringImpl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698