| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2013 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2013 Apple Inc. All rights reserv
ed. |
| 3 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> | 3 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> |
| 4 * Copyright (C) 2012 Google Inc. All rights reserved. | 4 * Copyright (C) 2012 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 template<typename T, typename HashTranslator> | 113 template<typename T, typename HashTranslator> |
| 114 static inline PassRefPtr<StringImpl> addToStringTable(const T& value) | 114 static inline PassRefPtr<StringImpl> addToStringTable(const T& value) |
| 115 { | 115 { |
| 116 HashSet<StringImpl*>::AddResult addResult = atomicStrings().add<HashTranslat
or>(value); | 116 HashSet<StringImpl*>::AddResult addResult = atomicStrings().add<HashTranslat
or>(value); |
| 117 | 117 |
| 118 // If the string is newly-translated, then we need to adopt it. | 118 // If the string is newly-translated, then we need to adopt it. |
| 119 // The boolean in the pair tells us if that is so. | 119 // The boolean in the pair tells us if that is so. |
| 120 return addResult.isNewEntry ? adoptRef(*addResult.storedValue) : *addResult.
storedValue; | 120 return addResult.isNewEntry ? adoptRef(*addResult.storedValue) : *addResult.
storedValue; |
| 121 } | 121 } |
| 122 | 122 |
| 123 struct CStringTranslator { | |
| 124 static unsigned hash(const LChar* c) | |
| 125 { | |
| 126 return StringHasher::computeHashAndMaskTop8Bits(c); | |
| 127 } | |
| 128 | |
| 129 static inline bool equal(StringImpl* r, const LChar* s) | |
| 130 { | |
| 131 return WTF::equal(r, s); | |
| 132 } | |
| 133 | |
| 134 static void translate(StringImpl*& location, const LChar* const& c, unsigned
hash) | |
| 135 { | |
| 136 location = StringImpl::create(c).leakRef(); | |
| 137 location->setHash(hash); | |
| 138 location->setIsAtomic(true); | |
| 139 } | |
| 140 }; | |
| 141 | |
| 142 PassRefPtr<StringImpl> AtomicString::add(const LChar* c) | 123 PassRefPtr<StringImpl> AtomicString::add(const LChar* c) |
| 143 { | 124 { |
| 144 if (!c) | 125 if (!c) |
| 145 return nullptr; | 126 return nullptr; |
| 146 if (!*c) | 127 if (!*c) |
| 147 return StringImpl::empty(); | 128 return StringImpl::empty(); |
| 148 | 129 |
| 149 return addToStringTable<const LChar*, CStringTranslator>(c); | 130 return add(c, strlen(reinterpret_cast<const char*>(c))); |
| 150 } | 131 } |
| 151 | 132 |
| 152 template<typename CharacterType> | 133 template<typename CharacterType> |
| 153 struct HashTranslatorCharBuffer { | 134 struct HashTranslatorCharBuffer { |
| 154 const CharacterType* s; | 135 const CharacterType* s; |
| 155 unsigned length; | 136 unsigned length; |
| 156 }; | 137 }; |
| 157 | 138 |
| 158 typedef HashTranslatorCharBuffer<UChar> UCharBuffer; | 139 typedef HashTranslatorCharBuffer<UChar> UCharBuffer; |
| 159 struct UCharBufferTranslator { | 140 struct UCharBufferTranslator { |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 } | 507 } |
| 527 | 508 |
| 528 #ifndef NDEBUG | 509 #ifndef NDEBUG |
| 529 void AtomicString::show() const | 510 void AtomicString::show() const |
| 530 { | 511 { |
| 531 m_string.show(); | 512 m_string.show(); |
| 532 } | 513 } |
| 533 #endif | 514 #endif |
| 534 | 515 |
| 535 } // namespace WTF | 516 } // namespace WTF |
| OLD | NEW |