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

Side by Side Diff: third_party/WebKit/Source/core/dom/CSSSelectorWatch.cpp

Issue 2553343002: Avoid WTF::Vector::at() and operator[] in core/dom. (Closed)
Patch Set: Created 4 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/dom/ClientRectList.cpp » ('j') | 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) 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 m_addedSelectors.clear(); 85 m_addedSelectors.clear();
86 m_removedSelectors.clear(); 86 m_removedSelectors.clear();
87 m_timerExpirations = 0; 87 m_timerExpirations = 0;
88 } 88 }
89 89
90 void CSSSelectorWatch::updateSelectorMatches( 90 void CSSSelectorWatch::updateSelectorMatches(
91 const Vector<String>& removedSelectors, 91 const Vector<String>& removedSelectors,
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 (const auto& selector : removedSelectors) {
96 const String& selector = removedSelectors[i];
97 if (!m_matchingCallbackSelectors.remove(selector)) 96 if (!m_matchingCallbackSelectors.remove(selector))
98 continue; 97 continue;
99 98
100 // Count reached 0. 99 // Count reached 0.
101 shouldUpdateTimer = true; 100 shouldUpdateTimer = true;
102 auto it = m_addedSelectors.find(selector); 101 auto it = m_addedSelectors.find(selector);
103 if (it != m_addedSelectors.end()) 102 if (it != m_addedSelectors.end())
104 m_addedSelectors.remove(it); 103 m_addedSelectors.remove(it);
105 else 104 else
106 m_removedSelectors.add(selector); 105 m_removedSelectors.add(selector);
107 } 106 }
108 107
109 for (unsigned i = 0; i < addedSelectors.size(); ++i) { 108 for (const auto& selector : addedSelectors) {
110 const String& selector = addedSelectors[i];
111 HashCountedSet<String>::AddResult result = 109 HashCountedSet<String>::AddResult result =
112 m_matchingCallbackSelectors.add(selector); 110 m_matchingCallbackSelectors.add(selector);
113 if (!result.isNewEntry) 111 if (!result.isNewEntry)
114 continue; 112 continue;
115 113
116 shouldUpdateTimer = true; 114 shouldUpdateTimer = true;
117 auto it = m_removedSelectors.find(selector); 115 auto it = m_removedSelectors.find(selector);
118 if (it != m_removedSelectors.end()) 116 if (it != m_removedSelectors.end())
119 m_removedSelectors.remove(it); 117 m_removedSelectors.remove(it);
120 else 118 else
(...skipping 23 matching lines...) Expand all
144 } 142 }
145 return true; 143 return true;
146 } 144 }
147 145
148 void CSSSelectorWatch::watchCSSSelectors(const Vector<String>& selectors) { 146 void CSSSelectorWatch::watchCSSSelectors(const Vector<String>& selectors) {
149 m_watchedCallbackSelectors.clear(); 147 m_watchedCallbackSelectors.clear();
150 148
151 StylePropertySet* callbackPropertySet = 149 StylePropertySet* callbackPropertySet =
152 ImmutableStylePropertySet::create(nullptr, 0, UASheetMode); 150 ImmutableStylePropertySet::create(nullptr, 0, UASheetMode);
153 151
154 for (unsigned i = 0; i < selectors.size(); ++i) { 152 for (const auto& selector : selectors) {
155 CSSSelectorList selectorList = CSSParser::parseSelector( 153 CSSSelectorList selectorList = CSSParser::parseSelector(
156 CSSParserContext(UASheetMode, nullptr), nullptr, selectors[i]); 154 CSSParserContext(UASheetMode, nullptr), nullptr, selector);
157 if (!selectorList.isValid()) 155 if (!selectorList.isValid())
158 continue; 156 continue;
159 157
160 // Only accept Compound Selectors, since they're cheaper to match. 158 // Only accept Compound Selectors, since they're cheaper to match.
161 if (!allCompound(selectorList)) 159 if (!allCompound(selectorList))
162 continue; 160 continue;
163 161
164 m_watchedCallbackSelectors.append( 162 m_watchedCallbackSelectors.append(
165 StyleRule::create(std::move(selectorList), callbackPropertySet)); 163 StyleRule::create(std::move(selectorList), callbackPropertySet));
166 } 164 }
167 document().styleEngine().watchedSelectorsChanged(); 165 document().styleEngine().watchedSelectorsChanged();
168 } 166 }
169 167
170 DEFINE_TRACE(CSSSelectorWatch) { 168 DEFINE_TRACE(CSSSelectorWatch) {
171 visitor->trace(m_watchedCallbackSelectors); 169 visitor->trace(m_watchedCallbackSelectors);
172 visitor->trace(m_document); 170 visitor->trace(m_document);
173 Supplement<Document>::trace(visitor); 171 Supplement<Document>::trace(visitor);
174 } 172 }
175 173
176 } // namespace blink 174 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/dom/ClientRectList.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698