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

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

Issue 1370113006: AtomicStringTable should not be initialized lazily Base URL: https://chromium.googlesource.com/chromium/src.git@AtomitStringTable
Patch Set: Export AtomicStringTable 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/AtomicString.h ('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/AtomicString.cpp
diff --git a/third_party/WebKit/Source/wtf/text/AtomicString.cpp b/third_party/WebKit/Source/wtf/text/AtomicString.cpp
index d3888ecf1577d73ab69106e8243c97982ea5ca59..3141a86ef91e24f17d4a16ecdefe26d4eda2a297 100644
--- a/third_party/WebKit/Source/wtf/text/AtomicString.cpp
+++ b/third_party/WebKit/Source/wtf/text/AtomicString.cpp
@@ -24,7 +24,6 @@
#include "AtomicString.h"
#include "StringHash.h"
-#include "wtf/HashSet.h"
#include "wtf/WTFThreadData.h"
#include "wtf/dtoa.h"
#include "wtf/text/IntegerToStringConversion.h"
@@ -36,78 +35,52 @@ using namespace Unicode;
static_assert(sizeof(AtomicString) == sizeof(String), "AtomicString and String must be same size");
-class AtomicStringTable {
- WTF_MAKE_NONCOPYABLE(AtomicStringTable);
-public:
- static AtomicStringTable* create(WTFThreadData& data)
- {
- data.m_atomicStringTable = new AtomicStringTable;
- data.m_atomicStringTableDestructor = AtomicStringTable::destroy;
- data.m_atomicStringTable->addStaticStrings();
- return data.m_atomicStringTable;
- }
-
- StringImpl* addStringImpl(StringImpl* string)
- {
- if (!string->length())
- return StringImpl::empty();
-
- StringImpl* result = *m_table.add(string).storedValue;
-
- if (!result->isAtomic())
- result->setIsAtomic(true);
-
- ASSERT(!string->isStatic() || result->isStatic());
- return result;
- }
+StringImpl* AtomicStringTable::addStringImpl(StringImpl* string)
+{
+ if (!string->length())
+ return StringImpl::empty();
- HashSet<StringImpl*>& table()
- {
- return m_table;
- }
+ StringImpl* result = *m_table.add(string).storedValue;
-private:
- AtomicStringTable() { }
+ if (!result->isAtomic())
+ result->setIsAtomic(true);
- void addStaticStrings()
- {
- const StaticStringsTable& staticStrings = StringImpl::allStaticStrings();
+ ASSERT(!string->isStatic() || result->isStatic());
+ return result;
+}
- StaticStringsTable::const_iterator it = staticStrings.begin();
- for (; it != staticStrings.end(); ++it) {
- addStringImpl(it->value);
- }
+AtomicStringTable* AtomicStringTable::create()
+{
+ AtomicStringTable* table = new AtomicStringTable;
+ const StaticStringsTable& staticStrings = StringImpl::allStaticStrings();
+ for (auto it = staticStrings.begin(); it != staticStrings.end(); ++it) {
+ table->addStringImpl(it->value);
}
+ return table;
+}
- static void destroy(AtomicStringTable* table)
- {
- HashSet<StringImpl*>::iterator end = table->m_table.end();
- for (HashSet<StringImpl*>::iterator iter = table->m_table.begin(); iter != end; ++iter) {
- StringImpl* string = *iter;
- if (!string->isStatic()) {
- ASSERT(string->isAtomic());
- string->setIsAtomic(false);
- }
+void AtomicStringTable::destroy(AtomicStringTable* table)
+{
+ for (StringImpl* string : table->table()) {
+ if (!string->isStatic()) {
+ ASSERT(string->isAtomic());
+ string->setIsAtomic(false);
}
- delete table;
}
+ delete table;
+}
- HashSet<StringImpl*> m_table;
-};
-
-static inline AtomicStringTable& atomicStringTable()
+static inline AtomicStringTable* atomicStringTable()
{
- // Once possible we should make this non-lazy (constructed in WTFThreadData's constructor).
WTFThreadData& data = wtfThreadData();
AtomicStringTable* table = data.atomicStringTable();
- if (UNLIKELY(!table))
- table = AtomicStringTable::create(data);
- return *table;
+ ASSERT(table);
+ return table;
}
static inline HashSet<StringImpl*>& atomicStrings()
{
- return atomicStringTable().table();
+ return atomicStringTable()->table();
}
template<typename T, typename HashTranslator>
@@ -405,7 +378,7 @@ PassRefPtr<StringImpl> AtomicString::addFromLiteralData(const char* characters,
PassRefPtr<StringImpl> AtomicString::addSlowCase(StringImpl* string)
{
- return atomicStringTable().addStringImpl(string);
+ return atomicStringTable()->addStringImpl(string);
}
template<typename CharacterType>
« no previous file with comments | « third_party/WebKit/Source/wtf/text/AtomicString.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698