Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008, 2010 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008 David Smith <catfish.man@gmail.com> | 3 * Copyright (C) 2008 David Smith <catfish.man@gmail.com> |
| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 template <typename StringType> | 87 template <typename StringType> |
| 88 struct NodeListCacheMapEntryHash { | 88 struct NodeListCacheMapEntryHash { |
| 89 static unsigned hash(const std::pair<unsigned char, StringType>& entry) | 89 static unsigned hash(const std::pair<unsigned char, StringType>& entry) |
| 90 { | 90 { |
| 91 return DefaultHash<StringType>::Hash::hash(entry.second) + entry.fir st; | 91 return DefaultHash<StringType>::Hash::hash(entry.second) + entry.fir st; |
| 92 } | 92 } |
| 93 static bool equal(const std::pair<unsigned char, StringType>& a, const s td::pair<unsigned char, StringType>& b) { return a == b; } | 93 static bool equal(const std::pair<unsigned char, StringType>& a, const s td::pair<unsigned char, StringType>& b) { return a == b; } |
| 94 static const bool safeToCompareToEmptyOrDeleted = DefaultHash<StringType >::Hash::safeToCompareToEmptyOrDeleted; | 94 static const bool safeToCompareToEmptyOrDeleted = DefaultHash<StringType >::Hash::safeToCompareToEmptyOrDeleted; |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 typedef HashMap<std::pair<unsigned char, AtomicString>, LiveNodeListBase*, N odeListCacheMapEntryHash<AtomicString> > NodeListAtomicNameCacheMap; | 97 struct NodeListAtomicCacheMapEntryHash { |
| 98 static unsigned hash(const std::pair<unsigned char, StringImpl*>& entry) | |
| 99 { | |
| 100 return DefaultHash<StringImpl*>::Hash::hash(entry.second) + entry.fi rst; | |
| 101 } | |
| 102 static bool equal(const std::pair<unsigned char, StringImpl*>& a, const std::pair<unsigned char, StringImpl*>& b) { return a == b; } | |
| 103 static const bool safeToCompareToEmptyOrDeleted = DefaultHash<StringImpl *>::Hash::safeToCompareToEmptyOrDeleted; | |
| 104 }; | |
| 105 | |
| 106 typedef HashMap<std::pair<unsigned char, StringImpl*>, LiveNodeListBase*, No deListAtomicCacheMapEntryHash> NodeListAtomicNameCacheMap; | |
| 98 typedef HashMap<std::pair<unsigned char, String>, LiveNodeListBase*, NodeLis tCacheMapEntryHash<String> > NodeListNameCacheMap; | 107 typedef HashMap<std::pair<unsigned char, String>, LiveNodeListBase*, NodeLis tCacheMapEntryHash<String> > NodeListNameCacheMap; |
| 99 typedef HashMap<QualifiedName, TagCollection*> TagCollectionCacheNS; | 108 typedef HashMap<QualifiedName, TagCollection*> TagCollectionCacheNS; |
| 100 | 109 |
| 101 template<typename T> | 110 template<typename T> |
| 102 PassRefPtr<T> addCacheWithAtomicName(ContainerNode* node, CollectionType col lectionType, const AtomicString& name) | 111 PassRefPtr<T> addCacheWithAtomicName(ContainerNode* node, CollectionType col lectionType, const AtomicString& name) |
| 103 { | 112 { |
| 104 NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(na medNodeListKey(collectionType, name), 0); | 113 NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(na medNodeListKey(collectionType, name), 0); |
| 105 if (!result.isNewEntry) | 114 if (!result.isNewEntry) |
| 106 return static_cast<T*>(result.iterator->value); | 115 return static_cast<T*>(result.iterator->value); |
| 107 | 116 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 newDocument.registerNodeList(list); | 230 newDocument.registerNodeList(list); |
| 222 } | 231 } |
| 223 } | 232 } |
| 224 } | 233 } |
| 225 | 234 |
| 226 private: | 235 private: |
| 227 NodeListsNodeData() | 236 NodeListsNodeData() |
| 228 : m_childNodeList(0) | 237 : m_childNodeList(0) |
| 229 { } | 238 { } |
| 230 | 239 |
| 231 std::pair<unsigned char, AtomicString> namedNodeListKey(CollectionType type, const AtomicString& name) | 240 std::pair<unsigned char, StringImpl*> namedNodeListKey(CollectionType type, const AtomicString& name) |
| 232 { | 241 { |
| 233 return std::pair<unsigned char, AtomicString>(type, name); | 242 return std::pair<unsigned char, StringImpl*>(type, name.impl()); |
|
abarth-chromium
2014/02/09 03:46:27
Why is this memory safe? What retains |name| ?
Inactive
2014/02/09 14:06:54
Nothing retains name. This is safe because we are
Inactive
2014/02/09 14:28:02
Never mind my previous comment, it is inaccurate.
| |
| 234 } | 243 } |
| 235 | 244 |
| 236 std::pair<unsigned char, String> namedNodeListKey(CollectionType type, const String& name) | 245 std::pair<unsigned char, String> namedNodeListKey(CollectionType type, const String& name) |
| 237 { | 246 { |
| 238 return std::pair<unsigned char, String>(type, name); | 247 return std::pair<unsigned char, String>(type, name); |
| 239 } | 248 } |
| 240 | 249 |
| 241 bool deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(Node*); | 250 bool deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(Node*); |
| 242 | 251 |
| 243 // Can be a ChildNodeList or an EmptyNodeList. | 252 // Can be a ChildNodeList or an EmptyNodeList. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 ownerNode->clearNodeLists(); | 324 ownerNode->clearNodeLists(); |
| 316 return true; | 325 return true; |
| 317 } | 326 } |
| 318 | 327 |
| 319 // Ensure the 10 bits reserved for the m_connectedFrameCount cannot overflow | 328 // Ensure the 10 bits reserved for the m_connectedFrameCount cannot overflow |
| 320 COMPILE_ASSERT(Page::maxNumberOfFrames < 1024, Frame_limit_should_fit_in_rare_da ta_count); | 329 COMPILE_ASSERT(Page::maxNumberOfFrames < 1024, Frame_limit_should_fit_in_rare_da ta_count); |
| 321 | 330 |
| 322 } // namespace WebCore | 331 } // namespace WebCore |
| 323 | 332 |
| 324 #endif // NodeRareData_h | 333 #endif // NodeRareData_h |
| OLD | NEW |