Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: Source/core/dom/NodeRareData.h

Issue 141743010: Use a StringImpl* instead of an AtomicString for NodeListAtomicNameCacheMap's key (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add comment Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 // Holding the raw StringImpl is safe because |name| is retained by the NodeList and the NodeList
243 // is reponsible for removing itself from the cache on deletion.
244 return std::pair<unsigned char, StringImpl*>(type, name.impl());
234 } 245 }
235 246
236 std::pair<unsigned char, String> namedNodeListKey(CollectionType type, const String& name) 247 std::pair<unsigned char, String> namedNodeListKey(CollectionType type, const String& name)
237 { 248 {
238 return std::pair<unsigned char, String>(type, name); 249 return std::pair<unsigned char, String>(type, name);
239 } 250 }
240 251
241 bool deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(Node*); 252 bool deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(Node*);
242 253
243 // Can be a ChildNodeList or an EmptyNodeList. 254 // Can be a ChildNodeList or an EmptyNodeList.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 ownerNode->clearNodeLists(); 326 ownerNode->clearNodeLists();
316 return true; 327 return true;
317 } 328 }
318 329
319 // Ensure the 10 bits reserved for the m_connectedFrameCount cannot overflow 330 // 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); 331 COMPILE_ASSERT(Page::maxNumberOfFrames < 1024, Frame_limit_should_fit_in_rare_da ta_count);
321 332
322 } // namespace WebCore 333 } // namespace WebCore
323 334
324 #endif // NodeRareData_h 335 #endif // NodeRareData_h
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698