| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 David Smith (catfish.man@gmail.com) | 2 * Copyright (C) 2007 David Smith (catfish.man@gmail.com) |
| 3 * Copyright (C) 2007, 2008, 2011, 2012 Apple Inc. All rights reserved. | 3 * Copyright (C) 2007, 2008, 2011, 2012 Apple Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 static inline bool hasNonASCIIOrUpper(const String& string) | 46 static inline bool hasNonASCIIOrUpper(const String& string) |
| 47 { | 47 { |
| 48 unsigned length = string.length(); | 48 unsigned length = string.length(); |
| 49 | 49 |
| 50 if (string.is8Bit()) | 50 if (string.is8Bit()) |
| 51 return hasNonASCIIOrUpper(string.characters8(), length); | 51 return hasNonASCIIOrUpper(string.characters8(), length); |
| 52 return hasNonASCIIOrUpper(string.characters16(), length); | 52 return hasNonASCIIOrUpper(string.characters16(), length); |
| 53 } | 53 } |
| 54 | 54 |
| 55 template <typename CharacterType> | 55 template <typename CharacterType> |
| 56 inline void SpaceSplitStringData::createVector(const CharacterType* characters,
unsigned length) | 56 inline void SpaceSplitString::Data::createVector(const CharacterType* characters
, unsigned length) |
| 57 { | 57 { |
| 58 unsigned start = 0; | 58 unsigned start = 0; |
| 59 while (true) { | 59 while (true) { |
| 60 while (start < length && isHTMLSpace<CharacterType>(characters[start])) | 60 while (start < length && isHTMLSpace<CharacterType>(characters[start])) |
| 61 ++start; | 61 ++start; |
| 62 if (start >= length) | 62 if (start >= length) |
| 63 break; | 63 break; |
| 64 unsigned end = start + 1; | 64 unsigned end = start + 1; |
| 65 while (end < length && isNotHTMLSpace<CharacterType>(characters[end])) | 65 while (end < length && isNotHTMLSpace<CharacterType>(characters[end])) |
| 66 ++end; | 66 ++end; |
| 67 | 67 |
| 68 m_vector.append(AtomicString(characters + start, end - start)); | 68 m_vector.append(AtomicString(characters + start, end - start)); |
| 69 | 69 |
| 70 start = end + 1; | 70 start = end + 1; |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 void SpaceSplitStringData::createVector(const String& string) | 74 void SpaceSplitString::Data::createVector(const String& string) |
| 75 { | 75 { |
| 76 unsigned length = string.length(); | 76 unsigned length = string.length(); |
| 77 | 77 |
| 78 if (string.is8Bit()) { | 78 if (string.is8Bit()) { |
| 79 createVector(string.characters8(), length); | 79 createVector(string.characters8(), length); |
| 80 return; | 80 return; |
| 81 } | 81 } |
| 82 | 82 |
| 83 createVector(string.characters16(), length); | 83 createVector(string.characters16(), length); |
| 84 } | 84 } |
| 85 | 85 |
| 86 bool SpaceSplitStringData::containsAll(SpaceSplitStringData& other) | 86 bool SpaceSplitString::Data::containsAll(Data& other) |
| 87 { | 87 { |
| 88 if (this == &other) | 88 if (this == &other) |
| 89 return true; | 89 return true; |
| 90 | 90 |
| 91 size_t thisSize = m_vector.size(); | 91 size_t thisSize = m_vector.size(); |
| 92 size_t otherSize = other.m_vector.size(); | 92 size_t otherSize = other.m_vector.size(); |
| 93 for (size_t i = 0; i < otherSize; ++i) { | 93 for (size_t i = 0; i < otherSize; ++i) { |
| 94 const AtomicString& name = other.m_vector[i]; | 94 const AtomicString& name = other.m_vector[i]; |
| 95 size_t j; | 95 size_t j; |
| 96 for (j = 0; j < thisSize; ++j) { | 96 for (j = 0; j < thisSize; ++j) { |
| 97 if (m_vector[j] == name) | 97 if (m_vector[j] == name) |
| 98 break; | 98 break; |
| 99 } | 99 } |
| 100 if (j == thisSize) | 100 if (j == thisSize) |
| 101 return false; | 101 return false; |
| 102 } | 102 } |
| 103 return true; | 103 return true; |
| 104 } | 104 } |
| 105 | 105 |
| 106 void SpaceSplitStringData::add(const AtomicString& string) | 106 void SpaceSplitString::Data::add(const AtomicString& string) |
| 107 { | 107 { |
| 108 ASSERT(hasOneRef()); | 108 ASSERT(hasOneRef()); |
| 109 ASSERT(!contains(string)); | 109 ASSERT(!contains(string)); |
| 110 m_vector.append(string); | 110 m_vector.append(string); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void SpaceSplitStringData::remove(unsigned index) | 113 void SpaceSplitString::Data::remove(unsigned index) |
| 114 { | 114 { |
| 115 ASSERT(hasOneRef()); | 115 ASSERT(hasOneRef()); |
| 116 m_vector.remove(index); | 116 m_vector.remove(index); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void SpaceSplitString::add(const AtomicString& string) | 119 void SpaceSplitString::add(const AtomicString& string) |
| 120 { | 120 { |
| 121 // FIXME: add() does not allow duplicates but createVector() does. | 121 // FIXME: add() does not allow duplicates but createVector() does. |
| 122 if (contains(string)) | 122 if (contains(string)) |
| 123 return; | 123 return; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 138 ensureUnique(); | 138 ensureUnique(); |
| 139 m_data->remove(i); | 139 m_data->remove(i); |
| 140 changed = true; | 140 changed = true; |
| 141 continue; | 141 continue; |
| 142 } | 142 } |
| 143 ++i; | 143 ++i; |
| 144 } | 144 } |
| 145 return changed; | 145 return changed; |
| 146 } | 146 } |
| 147 | 147 |
| 148 typedef HashMap<AtomicString, SpaceSplitStringData*> SpaceSplitStringDataMap; | 148 SpaceSplitString::DataMap& SpaceSplitString::sharedDataMap() |
| 149 | |
| 150 static SpaceSplitStringDataMap& sharedDataMap() | |
| 151 { | 149 { |
| 152 DEFINE_STATIC_LOCAL(SpaceSplitStringDataMap, map, ()); | 150 DEFINE_STATIC_LOCAL(DataMap, map, ()); |
| 153 return map; | 151 return map; |
| 154 } | 152 } |
| 155 | 153 |
| 156 void SpaceSplitString::set(const AtomicString& inputString, bool shouldFoldCase) | 154 void SpaceSplitString::set(const AtomicString& inputString, bool shouldFoldCase) |
| 157 { | 155 { |
| 158 if (inputString.isNull()) { | 156 if (inputString.isNull()) { |
| 159 clear(); | 157 clear(); |
| 160 return; | 158 return; |
| 161 } | 159 } |
| 162 | 160 |
| 163 String string(inputString.string()); | 161 String string(inputString.string()); |
| 164 if (shouldFoldCase && hasNonASCIIOrUpper(string)) | 162 if (shouldFoldCase && hasNonASCIIOrUpper(string)) |
| 165 string = string.foldCase(); | 163 string = string.foldCase(); |
| 166 | 164 |
| 167 m_data = SpaceSplitStringData::create(AtomicString(string)); | 165 m_data = Data::create(AtomicString(string)); |
| 168 } | 166 } |
| 169 | 167 |
| 170 SpaceSplitStringData::~SpaceSplitStringData() | 168 SpaceSplitString::Data::~Data() |
| 171 { | 169 { |
| 172 if (!m_keyString.isNull()) | 170 if (!m_keyString.isNull()) |
| 173 sharedDataMap().remove(m_keyString); | 171 sharedDataMap().remove(m_keyString); |
| 174 } | 172 } |
| 175 | 173 |
| 176 PassRefPtr<SpaceSplitStringData> SpaceSplitStringData::create(const AtomicString
& string) | 174 PassRefPtr<SpaceSplitString::Data> SpaceSplitString::Data::create(const AtomicSt
ring& string) |
| 177 { | 175 { |
| 178 SpaceSplitStringData*& data = sharedDataMap().add(string, 0).storedValue->va
lue; | 176 Data*& data = sharedDataMap().add(string, 0).storedValue->value; |
| 179 if (!data) { | 177 if (!data) { |
| 180 data = new SpaceSplitStringData(string); | 178 data = new Data(string); |
| 181 return adoptRef(data); | 179 return adoptRef(data); |
| 182 } | 180 } |
| 183 return data; | 181 return data; |
| 184 } | 182 } |
| 185 | 183 |
| 186 PassRefPtr<SpaceSplitStringData> SpaceSplitStringData::createUnique(const SpaceS
plitStringData& other) | 184 PassRefPtr<SpaceSplitString::Data> SpaceSplitString::Data::createUnique(const Da
ta& other) |
| 187 { | 185 { |
| 188 return adoptRef(new SpaceSplitStringData(other)); | 186 return adoptRef(new SpaceSplitString::Data(other)); |
| 189 } | 187 } |
| 190 | 188 |
| 191 SpaceSplitStringData::SpaceSplitStringData(const AtomicString& string) | 189 SpaceSplitString::Data::Data(const AtomicString& string) |
| 192 : m_keyString(string) | 190 : m_keyString(string) |
| 193 { | 191 { |
| 194 ASSERT(!string.isNull()); | 192 ASSERT(!string.isNull()); |
| 195 createVector(string); | 193 createVector(string); |
| 196 } | 194 } |
| 197 | 195 |
| 198 SpaceSplitStringData::SpaceSplitStringData(const SpaceSplitStringData& other) | 196 SpaceSplitString::Data::Data(const SpaceSplitString::Data& other) |
| 199 : RefCounted<SpaceSplitStringData>() | 197 : RefCounted<Data>() |
| 200 , m_vector(other.m_vector) | 198 , m_vector(other.m_vector) |
| 201 { | 199 { |
| 202 // Note that we don't copy m_keyString to indicate to the destructor that th
ere's nothing | 200 // Note that we don't copy m_keyString to indicate to the destructor that th
ere's nothing |
| 203 // to be removed from the sharedDataMap(). | 201 // to be removed from the sharedDataMap(). |
| 204 } | 202 } |
| 205 | 203 |
| 206 } // namespace blink | 204 } // namespace blink |
| OLD | NEW |