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

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

Issue 117313002: Simplify DocumentOrderedMap (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 Element* getElementById(StringImpl*, const TreeScope*) const; 52 Element* getElementById(StringImpl*, const TreeScope*) const;
53 Element* getElementByMapName(StringImpl*, const TreeScope*) const; 53 Element* getElementByMapName(StringImpl*, const TreeScope*) const;
54 Element* getElementByLowercasedMapName(StringImpl*, const TreeScope*) const; 54 Element* getElementByLowercasedMapName(StringImpl*, const TreeScope*) const;
55 Element* getElementByLabelForAttribute(StringImpl*, const TreeScope*) const; 55 Element* getElementByLabelForAttribute(StringImpl*, const TreeScope*) const;
56 56
57 void checkConsistency() const; 57 void checkConsistency() const;
58 58
59 private: 59 private:
60 template<bool keyMatches(StringImpl*, Element*)> Element* get(StringImpl*, c onst TreeScope*) const; 60 template<bool keyMatches(StringImpl*, Element*)> Element* get(StringImpl*, c onst TreeScope*) const;
61 61
62 typedef HashMap<StringImpl*, Element*> Map; 62 struct MapEntry {
63 MapEntry()
64 : element(0)
65 , count(0)
66 { }
63 67
64 // We maintain the invariant that m_duplicateCounts is the count of all elem ents with a given key 68 explicit MapEntry(Element* firstElement)
65 // excluding the one referenced in m_map, if any. This means it one less tha n the total count 69 : element(firstElement)
66 // when the first node with a given key is cached, otherwise the same as the total count. 70 , count(1)
71 { }
72
73 Element* element;
74 unsigned count;
75 };
76
77 typedef HashMap<StringImpl*, MapEntry> Map;
78
67 mutable Map m_map; 79 mutable Map m_map;
68 mutable HashCountedSet<StringImpl*> m_duplicateCounts;
69 }; 80 };
70 81
71 inline bool DocumentOrderedMap::contains(StringImpl* id) const 82 inline bool DocumentOrderedMap::contains(StringImpl* id) const
72 { 83 {
73 return m_map.contains(id) || m_duplicateCounts.contains(id); 84 return m_map.contains(id);
74 } 85 }
75 86
76 inline bool DocumentOrderedMap::containsMultiple(StringImpl* id) const 87 inline bool DocumentOrderedMap::containsMultiple(StringImpl* id) const
77 { 88 {
78 return m_duplicateCounts.contains(id); 89 Map::const_iterator it = m_map.find(id);
90 return it != m_map.end() && it->value.count > 1;
79 } 91 }
80 92
81 } // namespace WebCore 93 } // namespace WebCore
82 94
83 #endif // DocumentOrderedMap_h 95 #endif // DocumentOrderedMap_h
OLDNEW
« no previous file with comments | « no previous file | Source/core/dom/DocumentOrderedMap.cpp » ('j') | Source/core/dom/DocumentOrderedMap.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698