| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #include "platform/wtf/text/AtomicStringTable.h" |
| 6 #define WTF_AtomicStringTable_h | |
| 7 | 6 |
| 8 #include "wtf/Allocator.h" | 7 // The contents of this header was moved to platform/wtf as part of |
| 9 #include "wtf/HashSet.h" | 8 // WTF migration project. See the following post for details: |
| 10 #include "wtf/WTFExport.h" | 9 // https://groups.google.com/a/chromium.org/d/msg/blink-dev/tLdAZCTlcAA/bYXVT8gY
CAAJ |
| 11 #include "wtf/WTFThreadData.h" | |
| 12 #include "wtf/text/StringHash.h" | |
| 13 #include "wtf/text/StringImpl.h" | |
| 14 | |
| 15 namespace WTF { | |
| 16 | |
| 17 // The underlying storage that keeps the map of unique AtomicStrings. This is | |
| 18 // not thread safe and each WTFThreadData has one. | |
| 19 class WTF_EXPORT AtomicStringTable final { | |
| 20 USING_FAST_MALLOC(AtomicStringTable); | |
| 21 WTF_MAKE_NONCOPYABLE(AtomicStringTable); | |
| 22 | |
| 23 public: | |
| 24 AtomicStringTable(); | |
| 25 ~AtomicStringTable(); | |
| 26 | |
| 27 // Gets the shared table for the current thread. | |
| 28 static AtomicStringTable& instance() { | |
| 29 return wtfThreadData().getAtomicStringTable(); | |
| 30 } | |
| 31 | |
| 32 // Used by system initialization to preallocate enough storage for all of | |
| 33 // the static strings. | |
| 34 void reserveCapacity(unsigned size); | |
| 35 | |
| 36 // Inserting strings into the table. Note that the return value from adding | |
| 37 // a UChar string may be an LChar string as the table will attempt to | |
| 38 // convert the string to save memory if possible. | |
| 39 StringImpl* add(StringImpl*); | |
| 40 PassRefPtr<StringImpl> add(const LChar* chars, unsigned length); | |
| 41 PassRefPtr<StringImpl> add(const UChar* chars, unsigned length); | |
| 42 | |
| 43 // Adding UTF8. | |
| 44 // Returns null if the characters contain invalid utf8 sequences. | |
| 45 // Pass null for the charactersEnd to automatically detect the length. | |
| 46 PassRefPtr<StringImpl> addUTF8(const char* charactersStart, | |
| 47 const char* charactersEnd); | |
| 48 | |
| 49 // This is for ~StringImpl to unregister a string before destruction since | |
| 50 // the table is holding weak pointers. It should not be used directly. | |
| 51 void remove(StringImpl*); | |
| 52 | |
| 53 private: | |
| 54 template <typename T, typename HashTranslator> | |
| 55 inline PassRefPtr<StringImpl> addToStringTable(const T& value); | |
| 56 | |
| 57 HashSet<StringImpl*> m_table; | |
| 58 }; | |
| 59 | |
| 60 } // namespace WTF | |
| 61 | |
| 62 using WTF::AtomicStringTable; | |
| 63 | |
| 64 #endif | |
| OLD | NEW |