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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 const Vector<String>& addedSelectors) { | 92 const Vector<String>& addedSelectors) { |
93 bool shouldUpdateTimer = false; | 93 bool shouldUpdateTimer = false; |
94 | 94 |
95 for (unsigned i = 0; i < removedSelectors.size(); ++i) { | 95 for (unsigned i = 0; i < removedSelectors.size(); ++i) { |
96 const String& selector = removedSelectors[i]; | 96 const String& selector = removedSelectors[i]; |
97 if (!m_matchingCallbackSelectors.remove(selector)) | 97 if (!m_matchingCallbackSelectors.remove(selector)) |
98 continue; | 98 continue; |
99 | 99 |
100 // Count reached 0. | 100 // Count reached 0. |
101 shouldUpdateTimer = true; | 101 shouldUpdateTimer = true; |
102 if (m_addedSelectors.contains(selector)) | 102 auto it = m_addedSelectors.find(selector); |
103 m_addedSelectors.remove(selector); | 103 if (it != m_addedSelectors.end()) |
| 104 m_addedSelectors.remove(it); |
104 else | 105 else |
105 m_removedSelectors.add(selector); | 106 m_removedSelectors.add(selector); |
106 } | 107 } |
107 | 108 |
108 for (unsigned i = 0; i < addedSelectors.size(); ++i) { | 109 for (unsigned i = 0; i < addedSelectors.size(); ++i) { |
109 const String& selector = addedSelectors[i]; | 110 const String& selector = addedSelectors[i]; |
110 HashCountedSet<String>::AddResult result = | 111 HashCountedSet<String>::AddResult result = |
111 m_matchingCallbackSelectors.add(selector); | 112 m_matchingCallbackSelectors.add(selector); |
112 if (!result.isNewEntry) | 113 if (!result.isNewEntry) |
113 continue; | 114 continue; |
114 | 115 |
115 shouldUpdateTimer = true; | 116 shouldUpdateTimer = true; |
116 if (m_removedSelectors.contains(selector)) | 117 auto it = m_removedSelectors.find(selector); |
117 m_removedSelectors.remove(selector); | 118 if (it != m_removedSelectors.end()) |
| 119 m_removedSelectors.remove(it); |
118 else | 120 else |
119 m_addedSelectors.add(selector); | 121 m_addedSelectors.add(selector); |
120 } | 122 } |
121 | 123 |
122 if (!shouldUpdateTimer) | 124 if (!shouldUpdateTimer) |
123 return; | 125 return; |
124 | 126 |
125 if (m_removedSelectors.isEmpty() && m_addedSelectors.isEmpty()) { | 127 if (m_removedSelectors.isEmpty() && m_addedSelectors.isEmpty()) { |
126 if (m_callbackSelectorChangeTimer.isActive()) { | 128 if (m_callbackSelectorChangeTimer.isActive()) { |
127 m_timerExpirations = 0; | 129 m_timerExpirations = 0; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 document().styleEngine().watchedSelectorsChanged(); | 167 document().styleEngine().watchedSelectorsChanged(); |
166 } | 168 } |
167 | 169 |
168 DEFINE_TRACE(CSSSelectorWatch) { | 170 DEFINE_TRACE(CSSSelectorWatch) { |
169 visitor->trace(m_watchedCallbackSelectors); | 171 visitor->trace(m_watchedCallbackSelectors); |
170 visitor->trace(m_document); | 172 visitor->trace(m_document); |
171 Supplement<Document>::trace(visitor); | 173 Supplement<Document>::trace(visitor); |
172 } | 174 } |
173 | 175 |
174 } // namespace blink | 176 } // namespace blink |
OLD | NEW |