OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights
reserved. | 3 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights
reserved. |
4 * Copyright (C) 2009 Google Inc. All rights reserved. | 4 * Copyright (C) 2009 Google Inc. All rights reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
11 * This library is distributed in the hope that it will be useful, | 11 * This library is distributed in the hope that it will be useful, |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 * Library General Public License for more details. | 14 * Library General Public License for more details. |
15 * | 15 * |
16 * You should have received a copy of the GNU Library General Public License | 16 * You should have received a copy of the GNU Library General Public License |
17 * along with this library; see the file COPYING.LIB. If not, write to | 17 * along with this library; see the file COPYING.LIB. If not, write to |
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 * Boston, MA 02110-1301, USA. | 19 * Boston, MA 02110-1301, USA. |
20 * | 20 * |
21 */ | 21 */ |
22 | 22 |
23 #ifndef StringImpl_h | 23 #ifndef StringImpl_h |
24 #define StringImpl_h | 24 #define StringImpl_h |
25 | 25 |
26 #include <limits.h> | 26 #include <limits.h> |
27 #include "wtf/ASCIICType.h" | 27 #include "wtf/ASCIICType.h" |
28 #include "wtf/Forward.h" | 28 #include "wtf/Forward.h" |
| 29 #include "wtf/HashMap.h" |
29 #include "wtf/StringHasher.h" | 30 #include "wtf/StringHasher.h" |
30 #include "wtf/Vector.h" | 31 #include "wtf/Vector.h" |
31 #include "wtf/WTFExport.h" | 32 #include "wtf/WTFExport.h" |
32 #include "wtf/unicode/Unicode.h" | 33 #include "wtf/unicode/Unicode.h" |
33 | 34 |
34 #if USE(CF) | 35 #if USE(CF) |
35 typedef const struct __CFString * CFStringRef; | 36 typedef const struct __CFString * CFStringRef; |
36 #endif | 37 #endif |
37 | 38 |
38 #ifdef __OBJC__ | 39 #ifdef __OBJC__ |
39 @class NSString; | 40 @class NSString; |
40 #endif | 41 #endif |
41 | 42 |
42 namespace WTF { | 43 namespace WTF { |
43 | 44 |
| 45 struct AlreadyHashed; |
44 struct CStringTranslator; | 46 struct CStringTranslator; |
45 template<typename CharacterType> struct HashAndCharactersTranslator; | 47 template<typename CharacterType> struct HashAndCharactersTranslator; |
46 struct HashAndUTF8CharactersTranslator; | 48 struct HashAndUTF8CharactersTranslator; |
47 struct LCharBufferTranslator; | 49 struct LCharBufferTranslator; |
48 struct CharBufferFromLiteralDataTranslator; | 50 struct CharBufferFromLiteralDataTranslator; |
49 struct SubstringTranslator; | 51 struct SubstringTranslator; |
50 struct UCharBufferTranslator; | 52 struct UCharBufferTranslator; |
51 template<typename> class RetainPtr; | 53 template<typename> class RetainPtr; |
52 | 54 |
53 enum TextCaseSensitivity { TextCaseSensitive, TextCaseInsensitive }; | 55 enum TextCaseSensitivity { TextCaseSensitive, TextCaseInsensitive }; |
54 | 56 |
55 enum StripBehavior { StripExtraWhiteSpace, DoNotStripWhiteSpace }; | 57 enum StripBehavior { StripExtraWhiteSpace, DoNotStripWhiteSpace }; |
56 | 58 |
57 typedef bool (*CharacterMatchFunctionPtr)(UChar); | 59 typedef bool (*CharacterMatchFunctionPtr)(UChar); |
58 typedef bool (*IsWhiteSpaceFunctionPtr)(UChar); | 60 typedef bool (*IsWhiteSpaceFunctionPtr)(UChar); |
| 61 typedef HashMap<unsigned, StringImpl*, AlreadyHashed> StaticStringsTable; |
59 | 62 |
60 // Define STRING_STATS to turn on run time statistics of string sizes and memory
usage | 63 // Define STRING_STATS to turn on run time statistics of string sizes and memory
usage |
61 #undef STRING_STATS | 64 #undef STRING_STATS |
62 | 65 |
63 #ifdef STRING_STATS | 66 #ifdef STRING_STATS |
64 struct StringStats { | 67 struct StringStats { |
65 inline void add8BitString(unsigned length) | 68 inline void add8BitString(unsigned length) |
66 { | 69 { |
67 ++m_totalNumberStrings; | 70 ++m_totalNumberStrings; |
68 ++m_number8BitStrings; | 71 ++m_number8BitStrings; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 , m_is8Bit(true) | 176 , m_is8Bit(true) |
174 , m_isStatic(true) | 177 , m_isStatic(true) |
175 { | 178 { |
176 } | 179 } |
177 | 180 |
178 public: | 181 public: |
179 ~StringImpl(); | 182 ~StringImpl(); |
180 | 183 |
181 static StringImpl* createStatic(const char* string, unsigned length, unsigne
d hash); | 184 static StringImpl* createStatic(const char* string, unsigned length, unsigne
d hash); |
182 static void freezeStaticStrings(); | 185 static void freezeStaticStrings(); |
183 static const Vector<StringImpl*>& allStaticStrings(); | 186 static const StaticStringsTable& allStaticStrings(); |
| 187 static unsigned highestStaticStringLength() { return m_highestStaticStringLe
ngth; } |
184 | 188 |
185 static PassRefPtr<StringImpl> create(const UChar*, unsigned length); | 189 static PassRefPtr<StringImpl> create(const UChar*, unsigned length); |
186 static PassRefPtr<StringImpl> create(const LChar*, unsigned length); | 190 static PassRefPtr<StringImpl> create(const LChar*, unsigned length); |
187 static PassRefPtr<StringImpl> create8BitIfPossible(const UChar*, unsigned le
ngth); | 191 static PassRefPtr<StringImpl> create8BitIfPossible(const UChar*, unsigned le
ngth); |
188 template<size_t inlineCapacity> | 192 template<size_t inlineCapacity> |
189 static PassRefPtr<StringImpl> create8BitIfPossible(const Vector<UChar, inlin
eCapacity>& vector) | 193 static PassRefPtr<StringImpl> create8BitIfPossible(const Vector<UChar, inlin
eCapacity>& vector) |
190 { | 194 { |
191 return create8BitIfPossible(vector.data(), vector.size()); | 195 return create8BitIfPossible(vector.data(), vector.size()); |
192 } | 196 } |
193 | 197 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 static const unsigned s_copyCharsInlineCutOff = 20; | 439 static const unsigned s_copyCharsInlineCutOff = 20; |
436 | 440 |
437 template <class UCharPredicate> PassRefPtr<StringImpl> stripMatchedCharacter
s(UCharPredicate); | 441 template <class UCharPredicate> PassRefPtr<StringImpl> stripMatchedCharacter
s(UCharPredicate); |
438 template <typename CharType, class UCharPredicate> PassRefPtr<StringImpl> si
mplifyMatchedCharactersToSpace(UCharPredicate, StripBehavior); | 442 template <typename CharType, class UCharPredicate> PassRefPtr<StringImpl> si
mplifyMatchedCharactersToSpace(UCharPredicate, StripBehavior); |
439 NEVER_INLINE unsigned hashSlowCase() const; | 443 NEVER_INLINE unsigned hashSlowCase() const; |
440 | 444 |
441 #ifdef STRING_STATS | 445 #ifdef STRING_STATS |
442 static StringStats m_stringStats; | 446 static StringStats m_stringStats; |
443 #endif | 447 #endif |
444 | 448 |
| 449 static unsigned m_highestStaticStringLength; |
| 450 |
445 #ifndef NDEBUG | 451 #ifndef NDEBUG |
446 void assertHashIsCorrect() | 452 void assertHashIsCorrect() |
447 { | 453 { |
448 ASSERT(hasHash()); | 454 ASSERT(hasHash()); |
449 ASSERT(existingHash() == StringHasher::computeHashAndMaskTop8Bits(charac
ters8(), length())); | 455 ASSERT(existingHash() == StringHasher::computeHashAndMaskTop8Bits(charac
ters8(), length())); |
450 } | 456 } |
451 #endif | 457 #endif |
452 | 458 |
453 private: | 459 private: |
454 unsigned m_refCount; | 460 unsigned m_refCount; |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 } | 752 } |
747 | 753 |
748 using WTF::StringImpl; | 754 using WTF::StringImpl; |
749 using WTF::equal; | 755 using WTF::equal; |
750 using WTF::equalNonNull; | 756 using WTF::equalNonNull; |
751 using WTF::TextCaseSensitivity; | 757 using WTF::TextCaseSensitivity; |
752 using WTF::TextCaseSensitive; | 758 using WTF::TextCaseSensitive; |
753 using WTF::TextCaseInsensitive; | 759 using WTF::TextCaseInsensitive; |
754 | 760 |
755 #endif | 761 #endif |
OLD | NEW |