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

Side by Side Diff: third_party/WebKit/Source/wtf/text/AtomicStringTable.h

Issue 2110813003: Move all the AtomicString table into AtomicStringTable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix comments. Created 4 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef WTF_AtomicStringTable_h 5 #ifndef WTF_AtomicStringTable_h
6 #define WTF_AtomicStringTable_h 6 #define WTF_AtomicStringTable_h
7 7
8 #include "wtf/Allocator.h" 8 #include "wtf/Allocator.h"
9 #include "wtf/HashSet.h" 9 #include "wtf/HashSet.h"
10 #include "wtf/WTFExport.h"
11 #include "wtf/WTFThreadData.h"
10 #include "wtf/text/StringHash.h" 12 #include "wtf/text/StringHash.h"
11 #include "wtf/text/StringImpl.h" 13 #include "wtf/text/StringImpl.h"
12 14
13 namespace WTF { 15 namespace WTF {
14 16
15 // The underlying storage that keeps the map of unique AtomicStrings. This is 17 // The underlying storage that keeps the map of unique AtomicStrings. This is
16 // not thread safe and each WTFThreadData has one. 18 // not thread safe and each WTFThreadData has one.
17 class AtomicStringTable { 19 class WTF_EXPORT AtomicStringTable final {
18 USING_FAST_MALLOC(AtomicStringTable); 20 USING_FAST_MALLOC(AtomicStringTable);
19 WTF_MAKE_NONCOPYABLE(AtomicStringTable); 21 WTF_MAKE_NONCOPYABLE(AtomicStringTable);
20 public: 22 public:
21 AtomicStringTable(); 23 AtomicStringTable();
22 ~AtomicStringTable(); 24 ~AtomicStringTable();
23 25
24 StringImpl* addStringImpl(StringImpl*); 26 // Gets the shared table for the current thread.
27 static AtomicStringTable& instance()
28 {
29 return wtfThreadData().getAtomicStringTable();
30 }
25 31
26 HashSet<StringImpl*>& table() { return m_table; } 32 // Used by system initialization to preallocate enough storage for all of
33 // the static strings.
34 void reserveCapacity(unsigned);
35
36 // Adding a StringImpl.
37 StringImpl* add(StringImpl*);
38 PassRefPtr<StringImpl> add(StringImpl*, unsigned offset, unsigned length);
39
40 // Adding an LChar.
41 PassRefPtr<StringImpl> add(const LChar*, unsigned length);
42
43 // Adding a UChar.
44 PassRefPtr<StringImpl> add(const UChar*, unsigned length);
45 PassRefPtr<StringImpl> add(const UChar*, unsigned length, unsigned existingH ash);
46 PassRefPtr<StringImpl> add(const UChar*);
47
48 // Adding UTF8.
49 // Returns null if the characters contain invalid utf8 sequences.
50 // Pass null for the charactersEnd to automatically detect the length.
51 PassRefPtr<StringImpl> addUTF8(const char* charactersStart, const char* char actersEnd);
52
53 // This is for ~StringImpl to unregister a string before destruction since
54 // the table is holding weak pointers. It should not be used directly.
55 void remove(StringImpl*);
27 56
28 private: 57 private:
58 template<typename T, typename HashTranslator>
59 inline PassRefPtr<StringImpl> addToStringTable(const T& value);
60
61 template<typename CharacterType>
62 inline HashSet<StringImpl*>::iterator find(const StringImpl*);
63
29 HashSet<StringImpl*> m_table; 64 HashSet<StringImpl*> m_table;
30 }; 65 };
31 66
32 } // namespace WTF 67 } // namespace WTF
33 68
69 using WTF::AtomicStringTable;
70
34 #endif 71 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/AtomicStringCF.cpp ('k') | third_party/WebKit/Source/wtf/text/AtomicStringTable.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698