Chromium Code Reviews| 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 * |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 bool isEmptyUnique() const | 456 bool isEmptyUnique() const |
| 457 { | 457 { |
| 458 return !length() && !isStatic(); | 458 return !length() && !isStatic(); |
| 459 } | 459 } |
| 460 | 460 |
| 461 bool hasTerminatingNullCharacter() const { return m_hashAndFlags & s_hashFla gHasTerminatingNullCharacter; } | 461 bool hasTerminatingNullCharacter() const { return m_hashAndFlags & s_hashFla gHasTerminatingNullCharacter; } |
| 462 | 462 |
| 463 bool isAtomic() const { return m_hashAndFlags & s_hashFlagIsAtomic; } | 463 bool isAtomic() const { return m_hashAndFlags & s_hashFlagIsAtomic; } |
| 464 void setIsAtomic(bool isAtomic) | 464 void setIsAtomic(bool isAtomic) |
| 465 { | 465 { |
| 466 ASSERT(!isStatic()); | |
| 467 if (isAtomic) | 466 if (isAtomic) |
| 468 m_hashAndFlags |= s_hashFlagIsAtomic; | 467 m_hashAndFlags |= s_hashFlagIsAtomic; |
| 469 else | 468 else |
| 470 m_hashAndFlags &= ~s_hashFlagIsAtomic; | 469 m_hashAndFlags &= ~s_hashFlagIsAtomic; |
| 471 } | 470 } |
| 472 | 471 |
| 472 bool isStatic() const { return m_refCount & s_refCountFlagIsStaticString; } | |
| 473 | |
| 473 #ifdef STRING_STATS | 474 #ifdef STRING_STATS |
| 474 bool isSubString() const { return bufferOwnership() == BufferSubstring; } | 475 bool isSubString() const { return bufferOwnership() == BufferSubstring; } |
| 475 #endif | 476 #endif |
| 476 | 477 |
| 477 private: | 478 private: |
| 478 // The high bits of 'hash' are always empty, but we prefer to store our flag s | 479 // The high bits of 'hash' are always empty, but we prefer to store our flag s |
| 479 // in the low bits because it makes them slightly more efficient to access. | 480 // in the low bits because it makes them slightly more efficient to access. |
| 480 // So, we shift left and right when setting and getting our hash code. | 481 // So, we shift left and right when setting and getting our hash code. |
| 481 void setHash(unsigned hash) const | 482 void setHash(unsigned hash) const |
| 482 { | 483 { |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 679 | 680 |
| 680 bool isASCIILiteral() const | 681 bool isASCIILiteral() const |
| 681 { | 682 { |
| 682 return is8Bit() && hasInternalBuffer() && reinterpret_cast<const void*>( m_data8) != reinterpret_cast<const void*>(this + 1); | 683 return is8Bit() && hasInternalBuffer() && reinterpret_cast<const void*>( m_data8) != reinterpret_cast<const void*>(this + 1); |
| 683 } | 684 } |
| 684 | 685 |
| 685 // This number must be at least 2 to avoid sharing empty, null as well as 1 character strings from SmallStrings. | 686 // This number must be at least 2 to avoid sharing empty, null as well as 1 character strings from SmallStrings. |
| 686 static const unsigned s_copyCharsInlineCutOff = 20; | 687 static const unsigned s_copyCharsInlineCutOff = 20; |
| 687 | 688 |
| 688 BufferOwnership bufferOwnership() const { return static_cast<BufferOwnership >(m_hashAndFlags & s_hashMaskBufferOwnership); } | 689 BufferOwnership bufferOwnership() const { return static_cast<BufferOwnership >(m_hashAndFlags & s_hashMaskBufferOwnership); } |
| 689 bool isStatic() const { return m_refCount & s_refCountFlagIsStaticString; } | |
| 690 template <class UCharPredicate> PassRefPtr<StringImpl> stripMatchedCharacter s(UCharPredicate); | 690 template <class UCharPredicate> PassRefPtr<StringImpl> stripMatchedCharacter s(UCharPredicate); |
| 691 template <typename CharType, class UCharPredicate> PassRefPtr<StringImpl> si mplifyMatchedCharactersToSpace(UCharPredicate); | 691 template <typename CharType, class UCharPredicate> PassRefPtr<StringImpl> si mplifyMatchedCharactersToSpace(UCharPredicate); |
| 692 WTF_EXPORT_STRING_API NEVER_INLINE const UChar* getData16SlowCase() const; | 692 WTF_EXPORT_STRING_API NEVER_INLINE const UChar* getData16SlowCase() const; |
| 693 WTF_EXPORT_PRIVATE NEVER_INLINE unsigned hashSlowCase() const; | 693 WTF_EXPORT_PRIVATE NEVER_INLINE unsigned hashSlowCase() const; |
| 694 | 694 |
| 695 // The bottom bit in the ref count indicates a static (immortal) string. | 695 // The bottom bit in the ref count indicates a static (immortal) string. |
| 696 static const unsigned s_refCountFlagIsStaticString = 0x1; | 696 static const unsigned s_refCountFlagIsStaticString = 0x1; |
| 697 static const unsigned s_refCountIncrement = 0x2; // This allows us to ref / deref without disturbing the static string flag. | 697 static const unsigned s_refCountIncrement = 0x2; // This allows us to ref / deref without disturbing the static string flag. |
| 698 | 698 |
| 699 // The bottom 8 bits in the hash are flags. | 699 // The bottom 8 bits in the hash are flags. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 712 #ifdef STRING_STATS | 712 #ifdef STRING_STATS |
| 713 WTF_EXPORTDATA static StringStats m_stringStats; | 713 WTF_EXPORTDATA static StringStats m_stringStats; |
| 714 #endif | 714 #endif |
| 715 | 715 |
| 716 public: | 716 public: |
| 717 struct StaticASCIILiteral { | 717 struct StaticASCIILiteral { |
| 718 // These member variables must match the layout of StringImpl. | 718 // These member variables must match the layout of StringImpl. |
| 719 unsigned m_refCount; | 719 unsigned m_refCount; |
| 720 unsigned m_length; | 720 unsigned m_length; |
| 721 const LChar* m_data8; | 721 const LChar* m_data8; |
| 722 void* m_buffer; | 722 const UChar* m_copyData16; |
|
eseidel
2013/04/10 20:53:50
I'm confused by the rename.
abarth-chromium
2013/04/10 21:00:51
It's related to the union on line 746. I changed
| |
| 723 unsigned m_hashAndFlags; | 723 unsigned m_hashAndFlags; |
| 724 | 724 |
| 725 // These values mimic ConstructFromLiteral. | 725 static const unsigned s_initialRefCount = s_refCountFlagIsStaticString; |
| 726 static const unsigned s_initialRefCount = s_refCountIncrement; | 726 static const unsigned s_initialFlags = s_hashFlag8BitBuffer | s_hashFlag Has16BitShadow | BufferInternal | s_hashFlagHasTerminatingNullCharacter; |
| 727 static const unsigned s_initialFlags = s_hashFlag8BitBuffer | BufferInte rnal | s_hashFlagHasTerminatingNullCharacter; | |
| 728 static const unsigned s_hashShift = s_flagCount; | 727 static const unsigned s_hashShift = s_flagCount; |
| 729 }; | 728 }; |
| 730 | 729 |
| 731 #ifndef NDEBUG | 730 #ifndef NDEBUG |
| 732 void assertHashIsCorrect() | 731 void assertHashIsCorrect() |
| 733 { | 732 { |
| 734 ASSERT(hasHash()); | 733 ASSERT(hasHash()); |
| 735 ASSERT(existingHash() == StringHasher::computeHashAndMaskTop8Bits(charac ters8(), length())); | 734 ASSERT(existingHash() == StringHasher::computeHashAndMaskTop8Bits(charac ters8(), length())); |
| 736 } | 735 } |
| 737 #endif | 736 #endif |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1274 } | 1273 } |
| 1275 | 1274 |
| 1276 using WTF::StringImpl; | 1275 using WTF::StringImpl; |
| 1277 using WTF::equal; | 1276 using WTF::equal; |
| 1278 using WTF::equalNonNull; | 1277 using WTF::equalNonNull; |
| 1279 using WTF::TextCaseSensitivity; | 1278 using WTF::TextCaseSensitivity; |
| 1280 using WTF::TextCaseSensitive; | 1279 using WTF::TextCaseSensitive; |
| 1281 using WTF::TextCaseInsensitive; | 1280 using WTF::TextCaseInsensitive; |
| 1282 | 1281 |
| 1283 #endif | 1282 #endif |
| OLD | NEW |