OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 m_removedSelectors.clear(); | 83 m_removedSelectors.clear(); |
84 m_timerExpirations = 0; | 84 m_timerExpirations = 0; |
85 } | 85 } |
86 | 86 |
87 void CSSSelectorWatch::updateSelectorMatches(const Vector<String>& removedSelect ors, const Vector<String>& addedSelectors) | 87 void CSSSelectorWatch::updateSelectorMatches(const Vector<String>& removedSelect ors, const Vector<String>& addedSelectors) |
88 { | 88 { |
89 bool shouldUpdateTimer = false; | 89 bool shouldUpdateTimer = false; |
90 | 90 |
91 for (unsigned i = 0; i < removedSelectors.size(); ++i) { | 91 for (unsigned i = 0; i < removedSelectors.size(); ++i) { |
92 const String& selector = removedSelectors[i]; | 92 const String& selector = removedSelectors[i]; |
93 HashMap<String, int>::iterator count = m_matchingCallbackSelectors.find( selector); | 93 if (!m_matchingCallbackSelectors.remove(selector)) |
94 if (count == m_matchingCallbackSelectors.end()) | |
95 continue; | 94 continue; |
96 --count->value; | |
97 if (!count->value) { | |
98 shouldUpdateTimer = true; | |
99 | 95 |
100 m_matchingCallbackSelectors.remove(count); | 96 // Count reached 0. |
101 if (m_addedSelectors.contains(selector)) | 97 shouldUpdateTimer = true; |
102 m_addedSelectors.remove(selector); | 98 if (m_addedSelectors.contains(selector)) |
eseidel
2013/11/11 22:24:31
Would itr = find(); remove(itr); be "faster"? Do
| |
103 else | 99 m_addedSelectors.remove(selector); |
104 m_removedSelectors.add(selector); | 100 else |
105 } | 101 m_removedSelectors.add(selector); |
106 } | 102 } |
107 | 103 |
108 for (unsigned i = 0; i < addedSelectors.size(); ++i) { | 104 for (unsigned i = 0; i < addedSelectors.size(); ++i) { |
109 const String& selector = addedSelectors[i]; | 105 const String& selector = addedSelectors[i]; |
110 HashMap<String, int>::iterator count = m_matchingCallbackSelectors.find( selector); | 106 HashCountedSet<String>::AddResult result = m_matchingCallbackSelectors.a dd(selector); |
111 if (count != m_matchingCallbackSelectors.end()) { | 107 if (!result.isNewEntry) |
112 ++count->value; | |
113 continue; | 108 continue; |
114 } | 109 |
115 shouldUpdateTimer = true; | 110 shouldUpdateTimer = true; |
116 | |
117 m_matchingCallbackSelectors.set(selector, 1); | |
118 if (m_removedSelectors.contains(selector)) | 111 if (m_removedSelectors.contains(selector)) |
119 m_removedSelectors.remove(selector); | 112 m_removedSelectors.remove(selector); |
120 else | 113 else |
121 m_addedSelectors.add(selector); | 114 m_addedSelectors.add(selector); |
122 } | 115 } |
123 | 116 |
124 if (!shouldUpdateTimer) | 117 if (!shouldUpdateTimer) |
125 return; | 118 return; |
126 | 119 |
127 if (m_removedSelectors.isEmpty() && m_addedSelectors.isEmpty()) { | 120 if (m_removedSelectors.isEmpty() && m_addedSelectors.isEmpty()) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 | 159 |
167 RefPtr<StyleRule> rule = StyleRule::create(); | 160 RefPtr<StyleRule> rule = StyleRule::create(); |
168 rule->wrapperAdoptSelectorList(selectorList); | 161 rule->wrapperAdoptSelectorList(selectorList); |
169 rule->setProperties(callbackPropertySet); | 162 rule->setProperties(callbackPropertySet); |
170 m_watchedCallbackSelectors.append(rule.release()); | 163 m_watchedCallbackSelectors.append(rule.release()); |
171 } | 164 } |
172 m_document.changedSelectorWatch(); | 165 m_document.changedSelectorWatch(); |
173 } | 166 } |
174 | 167 |
175 } // namespace WebCore | 168 } // namespace WebCore |
OLD | NEW |