Initialize AtomicStringTable in WTFThreadData's constructor
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Jun 2013 01:08:33 +0000 (01:08 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Jun 2013 01:08:33 +0000 (01:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=117671

Reviewed by Geoffrey Garen.

Extracted AtomicStringTable from AtomicString.cpp into AtomicStringTable.h/cpp
and made WTFThreadDada::WTFThreadData create the atomic string table for the thread.

This eliminates a branch from stringTable() in AtomicString.cpp.

* GNUmakefile.list.am:
* WTF.pro:
* WTF.vcxproj/WTF.vcxproj:
* WTF.vcxproj/WTF.vcxproj.filters:
* WTF.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
* wtf/WTFThreadData.cpp:
(WTF::WTFThreadData::WTFThreadData):
* wtf/text/AtomicString.cpp:
(WTF::stringTable):
* wtf/text/AtomicStringTable.cpp: Added.
(WTF::AtomicStringTable::create):
(WTF::AtomicStringTable::destroy):
* wtf/text/AtomicStringTable.h: Added.
(WTF::AtomicStringTable::table):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@151663 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/GNUmakefile.list.am
Source/WTF/WTF.pro
Source/WTF/WTF.vcxproj/WTF.vcxproj
Source/WTF/WTF.vcxproj/WTF.vcxproj.filters
Source/WTF/WTF.xcodeproj/project.pbxproj
Source/WTF/wtf/CMakeLists.txt
Source/WTF/wtf/WTFThreadData.cpp
Source/WTF/wtf/text/AtomicString.cpp
Source/WTF/wtf/text/AtomicStringTable.cpp [new file with mode: 0644]
Source/WTF/wtf/text/AtomicStringTable.h [new file with mode: 0644]

index a37277d7886c4977dfe649670b690d3c4393f482..1e48c6efd891e3ae359be7b0629ee3ca5c5d5838 100644 (file)
@@ -1,3 +1,31 @@
+2013-06-17  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Initialize AtomicStringTable in WTFThreadData's constructor
+        https://bugs.webkit.org/show_bug.cgi?id=117671
+
+        Reviewed by Geoffrey Garen.
+
+        Extracted AtomicStringTable from AtomicString.cpp into AtomicStringTable.h/cpp
+        and made WTFThreadDada::WTFThreadData create the atomic string table for the thread.
+
+        This eliminates a branch from stringTable() in AtomicString.cpp.
+
+        * GNUmakefile.list.am:
+        * WTF.pro:
+        * WTF.vcxproj/WTF.vcxproj:
+        * WTF.vcxproj/WTF.vcxproj.filters:
+        * WTF.xcodeproj/project.pbxproj:
+        * wtf/CMakeLists.txt:
+        * wtf/WTFThreadData.cpp:
+        (WTF::WTFThreadData::WTFThreadData):
+        * wtf/text/AtomicString.cpp:
+        (WTF::stringTable):
+        * wtf/text/AtomicStringTable.cpp: Added.
+        (WTF::AtomicStringTable::create):
+        (WTF::AtomicStringTable::destroy):
+        * wtf/text/AtomicStringTable.h: Added.
+        (WTF::AtomicStringTable::table):
+
 2013-06-17  Roger Fong  <roger_fong@apple.com>
 
         Modify Windows makefiles to copy some bin output into Program Files.
index 1d7f0b362a2ff5aaf34edc78665dc1a4ef358548..a6a00ee722db6ea7b2f2c73b2a4bffa6dff6cfec 100644 (file)
@@ -225,6 +225,8 @@ wtf_sources += \
     Source/WTF/wtf/text/AtomicString.h \
     Source/WTF/wtf/text/AtomicStringHash.h \
     Source/WTF/wtf/text/AtomicStringImpl.h \
+    Source/WTF/wtf/text/AtomicStringTable.cpp \
+    Source/WTF/wtf/text/AtomicStringTable.h \
     Source/WTF/wtf/text/Base64.cpp \
     Source/WTF/wtf/text/Base64.h \
     Source/WTF/wtf/text/CString.cpp \
index e3f90b87881b19c832d6a42bfdfdffc78157e7a9..2187e6dfe215c923135717e63c943c6f2d176b93 100644 (file)
@@ -144,6 +144,7 @@ HEADERS += \
     text/AtomicString.h \
     text/AtomicStringHash.h \
     text/AtomicStringImpl.h \
+    text/AtomicStringTable.h \
     text/Base64.h \
     text/CString.h \
     text/IntegerToStringConversion.h \
@@ -233,6 +234,7 @@ SOURCES += \
     TypeTraits.cpp \
     WTFThreadData.cpp \
     text/AtomicString.cpp \
+    text/AtomicStringTable.cpp \
     text/Base64.cpp \
     text/CString.cpp \
     text/StringBuilder.cpp \
index b684a5821c8c91fc7c7e37ca76fcd9ec3ce73106..45f539d55673313c9ef193ff35c2df2a0f2e7c23 100644 (file)
@@ -72,6 +72,7 @@
     <ClCompile Include="..\wtf\StringPrintStream.cpp" />\r
     <ClCompile Include="..\wtf\TCSystemAlloc.cpp" />\r
     <ClCompile Include="..\wtf\text\AtomicString.cpp" />\r
+    <ClCompile Include="..\wtf\text\AtomicStringTable.cpp" />\r
     <ClCompile Include="..\wtf\text\Base64.cpp" />\r
     <ClCompile Include="..\wtf\text\CString.cpp" />\r
     <ClCompile Include="..\wtf\text\StringBuilder.cpp" />\r
     <ClInclude Include="..\wtf\text\AtomicString.h" />\r
     <ClInclude Include="..\wtf\text\AtomicStringHash.h" />\r
     <ClInclude Include="..\wtf\text\AtomicStringImpl.h" />\r
+    <ClInclude Include="..\wtf\text\AtomicStringTable.h" />\r
     <ClInclude Include="..\wtf\text\Base64.h" />\r
     <ClInclude Include="..\wtf\text\CString.h" />\r
     <ClInclude Include="..\wtf\text\IntegerToStringConversion.h" />\r
index 027e07d70ee669cff6e289953594e1165c25654b..0b55548f52a3cf4d9ab0f54327d7a1ebafa27096 100644 (file)
     <ClInclude Include="..\wtf\text\AtomicStringImpl.h">\r
       <Filter>text</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="..\wtf\text\AtomicStringTable.h">\r
+      <Filter>text</Filter>\r
+    </ClInclude>\r
     <ClInclude Include="..\wtf\text\Base64.h">\r
       <Filter>text</Filter>\r
     </ClInclude>\r
index 5c2ba1fd7719675fd1bd71e7b5feb9ac17050f99..f0537afab5ee7e70d426685e24cd3ce55b0a1ef3 100644 (file)
@@ -54,6 +54,8 @@
                8134013815B092FD001FF0B8 /* Base64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8134013615B092FD001FF0B8 /* Base64.cpp */; };
                8134013915B092FD001FF0B8 /* Base64.h in Headers */ = {isa = PBXBuildFile; fileRef = 8134013715B092FD001FF0B8 /* Base64.h */; };
                974CFC8E16A4F327006D5404 /* WeakPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 974CFC8D16A4F327006D5404 /* WeakPtr.h */; };
+               9BC70F05176C379D00101DEC /* AtomicStringTable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9BC70F04176C379D00101DEC /* AtomicStringTable.cpp */; };
+               9BD8F40B176C2B470002D865 /* AtomicStringTable.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BD8F40A176C2AD80002D865 /* AtomicStringTable.h */; };
                A876DBD8151816E500DADB95 /* Platform.h in Headers */ = {isa = PBXBuildFile; fileRef = A876DBD7151816E500DADB95 /* Platform.h */; };
                A8A4737F151A825B004123FF /* Alignment.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A47254151A825A004123FF /* Alignment.h */; };
                A8A47381151A825B004123FF /* ArrayBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8A47256151A825A004123FF /* ArrayBuffer.cpp */; };
                8134013615B092FD001FF0B8 /* Base64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Base64.cpp; sourceTree = "<group>"; };
                8134013715B092FD001FF0B8 /* Base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Base64.h; sourceTree = "<group>"; };
                974CFC8D16A4F327006D5404 /* WeakPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakPtr.h; sourceTree = "<group>"; };
+               9BC70F04176C379D00101DEC /* AtomicStringTable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AtomicStringTable.cpp; sourceTree = "<group>"; };
+               9BD8F40A176C2AD80002D865 /* AtomicStringTable.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AtomicStringTable.h; sourceTree = "<group>"; };
                A876DBD7151816E500DADB95 /* Platform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Platform.h; sourceTree = "<group>"; };
                A8A47254151A825A004123FF /* Alignment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Alignment.h; sourceTree = "<group>"; };
                A8A47256151A825A004123FF /* ArrayBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ArrayBuffer.cpp; sourceTree = "<group>"; };
                                A8A4731E151A825B004123FF /* AtomicString.h */,
                                A8A4731F151A825B004123FF /* AtomicStringHash.h */,
                                A8A47320151A825B004123FF /* AtomicStringImpl.h */,
+                               9BD8F40A176C2AD80002D865 /* AtomicStringTable.h */,
+                               9BC70F04176C379D00101DEC /* AtomicStringTable.cpp */,
                                8134013615B092FD001FF0B8 /* Base64.cpp */,
                                8134013715B092FD001FF0B8 /* Base64.h */,
                                A8A47321151A825B004123FF /* CString.cpp */,
                                1469419216EAAF6D0024E146 /* RunLoopTimer.h in Headers */,
                                1469419616EAAFF80024E146 /* SchedulePair.h in Headers */,
                                A8A47385151A825B004123FF /* ASCIICType.h in Headers */,
+                               9BD8F40B176C2B470002D865 /* AtomicStringTable.h in Headers */,
                                A8A47434151A825B004123FF /* ASCIIFastPath.h in Headers */,
                                A8A47387151A825B004123FF /* Assertions.h in Headers */,
                                A8A47388151A825B004123FF /* Atomics.h in Headers */,
                                A8A47458151A825B004123FF /* TypeTraits.cpp in Sources */,
                                A8A47469151A825B004123FF /* UTF8.cpp in Sources */,
                                A8A47445151A825B004123FF /* WTFString.cpp in Sources */,
+                               9BC70F05176C379D00101DEC /* AtomicStringTable.cpp in Sources */,
                                A8A47486151A825B004123FF /* WTFThreadData.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
index 5bcd336ced2370891e53760e843c6e62086575aa..8667f12eb9cea9c2ab16369c0c77fc0bfac9bdf6 100644 (file)
@@ -126,6 +126,7 @@ set(WTF_HEADERS
 
     text/AtomicString.h
     text/AtomicStringImpl.h
+    text/AtomicStringTable.h
     text/Base64.h
     text/CString.h
     text/IntegerToStringConversion.h
@@ -192,6 +193,7 @@ set(WTF_SOURCES
     dtoa/strtod.cc
 
     text/AtomicString.cpp
+    text/AtomicStringTable.cpp
     text/Base64.cpp
     text/CString.cpp
     text/StringBuilder.cpp
index ec3e5003868469056fbee2de591a4e7a8b25816e..5c20181b279968904c60b3fd9d40a31bf4fac8e7 100644 (file)
@@ -27,6 +27,8 @@
 #include "config.h"
 #include "WTFThreadData.h"
 
+#include <wtf/text/AtomicStringTable.h>
+
 namespace WTF {
 
 ThreadSpecific<WTFThreadData>* WTFThreadData::staticData;
@@ -42,6 +44,7 @@ WTFThreadData::WTFThreadData()
     , m_stackStats()
 #endif
 {
+    AtomicStringTable::create(*this);
 }
 
 WTFThreadData::~WTFThreadData()
index c37eaf0c57b8f8e22946a97f073c931ce8817a3e..5ea127b159953a9cc9eb6d7d0be41cd3202c47fe 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "AtomicString.h"
 
+#include "AtomicStringTable.h"
 #include "StringHash.h"
 #include <wtf/HashSet.h>
 #include <wtf/Threading.h>
@@ -64,57 +65,9 @@ public:
 };
 #endif // USE(WEB_THREAD)
 
-class AtomicStringTable {
-    WTF_MAKE_FAST_ALLOCATED;
-public:
-    static AtomicStringTable* create(WTFThreadData& data)
-    {
-#if USE(WEB_THREAD)
-        // On iOS, one AtomicStringTable is shared between the main UI thread and the WebThread.
-        static AtomicStringTable* sharedStringTable = new AtomicStringTable;
-
-        bool currentThreadIsWebThread = isWebThread();
-        if (currentThreadIsWebThread || isUIThread())
-            data.m_atomicStringTable = sharedStringTable;
-        else
-            data.m_atomicStringTable = new AtomicStringTable;
-
-        // We do the following so that its destruction happens only
-        // once - on the main UI thread.
-        if (!currentThreadIsWebThread)
-            data.m_atomicStringTableDestructor = AtomicStringTable::destroy;
-#else
-        data.m_atomicStringTable = new AtomicStringTable;
-        data.m_atomicStringTableDestructor = AtomicStringTable::destroy;
-#endif // USE(WEB_THREAD)
-        return data.m_atomicStringTable;
-    }
-
-    HashSet<StringImpl*>& table()
-    {
-        return m_table;
-    }
-
-private:
-    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)
-            (*iter)->setIsAtomic(false);
-        delete table;
-    }
-
-    HashSet<StringImpl*> m_table;
-};
-
-static inline HashSet<StringImpl*>& stringTable()
+static ALWAYS_INLINE HashSet<StringImpl*>& stringTable()
 {
-    // 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->table();
+    return wtfThreadData().atomicStringTable()->table();
 }
 
 template<typename T, typename HashTranslator>
diff --git a/Source/WTF/wtf/text/AtomicStringTable.cpp b/Source/WTF/wtf/text/AtomicStringTable.cpp
new file mode 100644 (file)
index 0000000..fa1aa79
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+#include "AtomicStringTable.h"
+
+#include <wtf/HashSet.h>
+#include <wtf/WTFThreadData.h>
+
+namespace WTF {
+
+void AtomicStringTable::create(WTFThreadData& data)
+{
+#if USE(WEB_THREAD)
+    // On iOS, one AtomicStringTable is shared between the main UI thread and the WebThread.
+    static AtomicStringTable* sharedStringTable = new AtomicStringTable;
+
+    bool currentThreadIsWebThread = isWebThread();
+    if (currentThreadIsWebThread || isUIThread())
+        data.m_atomicStringTable = sharedStringTable;
+    else
+        data.m_atomicStringTable = new AtomicStringTable;
+
+    // We do the following so that its destruction happens only
+    // once - on the main UI thread.
+    if (!currentThreadIsWebThread)
+        data.m_atomicStringTableDestructor = destroyAtomicStringTable;
+#else
+    data.m_atomicStringTable = new AtomicStringTable;
+    data.m_atomicStringTableDestructor = AtomicStringTable::destroy;
+#endif // USE(WEB_THREAD)
+}
+
+void AtomicStringTable::destroy(AtomicStringTable* table)
+{
+    HashSet<StringImpl*>::iterator end = table->m_table.end();
+    for (HashSet<StringImpl*>::iterator iter = table->m_table.begin(); iter != end; ++iter)
+        (*iter)->setIsAtomic(false);
+    delete table;
+}
+
+}
diff --git a/Source/WTF/wtf/text/AtomicStringTable.h b/Source/WTF/wtf/text/AtomicStringTable.h
new file mode 100644 (file)
index 0000000..57826cb
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef WTF_AtomicStringTable_h
+#define WTF_AtomicStringTable_h
+
+#include <wtf/HashSet.h>
+#include <wtf/WTFThreadData.h>
+
+namespace WTF {
+
+class StringImpl;
+
+class AtomicStringTable {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+
+    static void create(WTFThreadData&);
+    HashSet<StringImpl*>& table() { return m_table; }
+
+private:
+    static void destroy(AtomicStringTable*);
+
+    HashSet<StringImpl*> m_table;
+};
+
+}
+
+#endif