| 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 | 3 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights |
| 4 * reserved. | 4 * reserved. |
| 5 * Copyright (C) 2009 Google Inc. All rights reserved. | 5 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 // features. | 62 // features. |
| 63 kTextCaseUnicodeInsensitive | 63 kTextCaseUnicodeInsensitive |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 enum StripBehavior { kStripExtraWhiteSpace, kDoNotStripWhiteSpace }; | 66 enum StripBehavior { kStripExtraWhiteSpace, kDoNotStripWhiteSpace }; |
| 67 | 67 |
| 68 typedef bool (*CharacterMatchFunctionPtr)(UChar); | 68 typedef bool (*CharacterMatchFunctionPtr)(UChar); |
| 69 typedef bool (*IsWhiteSpaceFunctionPtr)(UChar); | 69 typedef bool (*IsWhiteSpaceFunctionPtr)(UChar); |
| 70 typedef HashMap<unsigned, StringImpl*, AlreadyHashed> StaticStringsTable; | 70 typedef HashMap<unsigned, StringImpl*, AlreadyHashed> StaticStringsTable; |
| 71 | 71 |
| 72 // Define STRING_STATS to turn on run time statistics of string sizes and memory | |
| 73 // usage | |
| 74 #undef STRING_STATS | |
| 75 | |
| 76 #ifdef STRING_STATS | |
| 77 struct StringStats { | |
| 78 inline void add8BitString(unsigned length) { | |
| 79 ++m_totalNumberStrings; | |
| 80 ++m_number8BitStrings; | |
| 81 m_total8BitData += length; | |
| 82 } | |
| 83 | |
| 84 inline void add16BitString(unsigned length) { | |
| 85 ++m_totalNumberStrings; | |
| 86 ++m_number16BitStrings; | |
| 87 m_total16BitData += length; | |
| 88 } | |
| 89 | |
| 90 void removeString(StringImpl*); | |
| 91 void printStats(); | |
| 92 | |
| 93 static const unsigned s_printStringStatsFrequency = 5000; | |
| 94 static unsigned s_stringRemovesTillPrintStats; | |
| 95 | |
| 96 unsigned m_totalNumberStrings; | |
| 97 unsigned m_number8BitStrings; | |
| 98 unsigned m_number16BitStrings; | |
| 99 unsigned long long m_total8BitData; | |
| 100 unsigned long long m_total16BitData; | |
| 101 }; | |
| 102 | |
| 103 void addStringForStats(StringImpl*); | |
| 104 void removeStringForStats(StringImpl*); | |
| 105 | |
| 106 #define STRING_STATS_ADD_8BIT_STRING(length) \ | |
| 107 StringImpl::stringStats().add8BitString(length); \ | |
| 108 addStringForStats(this) | |
| 109 #define STRING_STATS_ADD_16BIT_STRING(length) \ | |
| 110 StringImpl::stringStats().add16BitString(length); \ | |
| 111 addStringForStats(this) | |
| 112 #define STRING_STATS_REMOVE_STRING(string) \ | |
| 113 StringImpl::stringStats().removeString(string); \ | |
| 114 removeStringForStats(this) | |
| 115 #else | |
| 116 #define STRING_STATS_ADD_8BIT_STRING(length) ((void)0) | |
| 117 #define STRING_STATS_ADD_16BIT_STRING(length) ((void)0) | |
| 118 #define STRING_STATS_REMOVE_STRING(string) ((void)0) | |
| 119 #endif | |
| 120 | |
| 121 // You can find documentation about this class in this doc: | 72 // You can find documentation about this class in this doc: |
| 122 // https://docs.google.com/document/d/1kOCUlJdh2WJMJGDf-WoEQhmnjKLaOYRbiHz5TiGJl
14/edit?usp=sharing | 73 // https://docs.google.com/document/d/1kOCUlJdh2WJMJGDf-WoEQhmnjKLaOYRbiHz5TiGJl
14/edit?usp=sharing |
| 123 class WTF_EXPORT StringImpl { | 74 class WTF_EXPORT StringImpl { |
| 124 WTF_MAKE_NONCOPYABLE(StringImpl); | 75 WTF_MAKE_NONCOPYABLE(StringImpl); |
| 125 | 76 |
| 126 private: | 77 private: |
| 127 // StringImpls are allocated out of the WTF buffer partition. | 78 // StringImpls are allocated out of the WTF buffer partition. |
| 128 void* operator new(size_t); | 79 void* operator new(size_t); |
| 129 void* operator new(size_t, void* ptr) { return ptr; } | 80 void* operator new(size_t, void* ptr) { return ptr; } |
| 130 void operator delete(void*); | 81 void operator delete(void*); |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 unsigned start = 0, | 424 unsigned start = 0, |
| 474 unsigned length = UINT_MAX) const; | 425 unsigned length = UINT_MAX) const; |
| 475 | 426 |
| 476 #if OS(MACOSX) | 427 #if OS(MACOSX) |
| 477 RetainPtr<CFStringRef> CreateCFString(); | 428 RetainPtr<CFStringRef> CreateCFString(); |
| 478 #endif | 429 #endif |
| 479 #ifdef __OBJC__ | 430 #ifdef __OBJC__ |
| 480 operator NSString*(); | 431 operator NSString*(); |
| 481 #endif | 432 #endif |
| 482 | 433 |
| 483 #ifdef STRING_STATS | |
| 484 ALWAYS_INLINE static StringStats& stringStats() { return m_stringStats; } | |
| 485 #endif | |
| 486 static const UChar kLatin1CaseFoldTable[256]; | 434 static const UChar kLatin1CaseFoldTable[256]; |
| 487 | 435 |
| 488 private: | 436 private: |
| 489 template <typename CharType> | 437 template <typename CharType> |
| 490 static size_t AllocationSize(unsigned length) { | 438 static size_t AllocationSize(unsigned length) { |
| 491 CHECK_LE(length, | 439 CHECK_LE(length, |
| 492 ((std::numeric_limits<unsigned>::max() - sizeof(StringImpl)) / | 440 ((std::numeric_limits<unsigned>::max() - sizeof(StringImpl)) / |
| 493 sizeof(CharType))); | 441 sizeof(CharType))); |
| 494 return sizeof(StringImpl) + length * sizeof(CharType); | 442 return sizeof(StringImpl) + length * sizeof(CharType); |
| 495 } | 443 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 508 StripBehavior); | 456 StripBehavior); |
| 509 NEVER_INLINE unsigned HashSlowCase() const; | 457 NEVER_INLINE unsigned HashSlowCase() const; |
| 510 | 458 |
| 511 void DestroyIfNotStatic() const; | 459 void DestroyIfNotStatic() const; |
| 512 void UpdateContainsOnlyASCII() const; | 460 void UpdateContainsOnlyASCII() const; |
| 513 | 461 |
| 514 #if DCHECK_IS_ON() | 462 #if DCHECK_IS_ON() |
| 515 std::string AsciiForDebugging() const; | 463 std::string AsciiForDebugging() const; |
| 516 #endif | 464 #endif |
| 517 | 465 |
| 518 #ifdef STRING_STATS | |
| 519 static StringStats m_stringStats; | |
| 520 #endif | |
| 521 | |
| 522 static unsigned highest_static_string_length_; | 466 static unsigned highest_static_string_length_; |
| 523 | 467 |
| 524 #if DCHECK_IS_ON() | 468 #if DCHECK_IS_ON() |
| 525 void AssertHashIsCorrect() { | 469 void AssertHashIsCorrect() { |
| 526 DCHECK(HasHash()); | 470 DCHECK(HasHash()); |
| 527 DCHECK_EQ(ExistingHash(), StringHasher::ComputeHashAndMaskTop8Bits( | 471 DCHECK_EQ(ExistingHash(), StringHasher::ComputeHashAndMaskTop8Bits( |
| 528 Characters8(), length())); | 472 Characters8(), length())); |
| 529 } | 473 } |
| 530 #endif | 474 #endif |
| 531 | 475 |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 using WTF::kTextCaseASCIIInsensitive; | 842 using WTF::kTextCaseASCIIInsensitive; |
| 899 using WTF::kTextCaseUnicodeInsensitive; | 843 using WTF::kTextCaseUnicodeInsensitive; |
| 900 using WTF::kTextCaseSensitive; | 844 using WTF::kTextCaseSensitive; |
| 901 using WTF::TextCaseSensitivity; | 845 using WTF::TextCaseSensitivity; |
| 902 using WTF::Equal; | 846 using WTF::Equal; |
| 903 using WTF::EqualNonNull; | 847 using WTF::EqualNonNull; |
| 904 using WTF::LengthOfNullTerminatedString; | 848 using WTF::LengthOfNullTerminatedString; |
| 905 using WTF::ReverseFind; | 849 using WTF::ReverseFind; |
| 906 | 850 |
| 907 #endif | 851 #endif |
| OLD | NEW |