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

Side by Side Diff: base/observer_list.h

Issue 8391003: Change O(n^2) loop to O(n) in ObserverListBase::Compact(). (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 9 years, 2 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 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_OBSERVER_LIST_H__ 5 #ifndef BASE_OBSERVER_LIST_H__
6 #define BASE_OBSERVER_LIST_H__ 6 #define BASE_OBSERVER_LIST_H__
7 #pragma once 7 #pragma once
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 155 }
156 } else { 156 } else {
157 observers_.clear(); 157 observers_.clear();
158 } 158 }
159 } 159 }
160 160
161 size_t size() const { return observers_.size(); } 161 size_t size() const { return observers_.size(); }
162 162
163 protected: 163 protected:
164 void Compact() { 164 void Compact() {
165 typename ListType::iterator it = observers_.begin(); 165 observers_.erase(
166 while (it != observers_.end()) { 166 std::remove(observers_.begin(), observers_.end(),
167 if (*it) { 167 static_cast<ObserverType*>(NULL)), observers_.end());
168 ++it;
169 } else {
170 it = observers_.erase(it);
171 }
172 }
173 } 168 }
174 169
175 private: 170 private:
176 friend class ObserverListThreadSafe<ObserverType>; 171 friend class ObserverListThreadSafe<ObserverType>;
177 172
178 typedef std::vector<ObserverType*> ListType; 173 typedef std::vector<ObserverType*> ListType;
179 174
180 ListType observers_; 175 ListType observers_;
181 int notify_depth_; 176 int notify_depth_;
182 NotificationType type_; 177 NotificationType type_;
(...skipping 30 matching lines...) Expand all
213 do { \ 208 do { \
214 if ((observer_list).might_have_observers()) { \ 209 if ((observer_list).might_have_observers()) { \
215 ObserverListBase<ObserverType>::Iterator it(observer_list); \ 210 ObserverListBase<ObserverType>::Iterator it(observer_list); \
216 ObserverType* obs; \ 211 ObserverType* obs; \
217 while ((obs = it.GetNext()) != NULL) \ 212 while ((obs = it.GetNext()) != NULL) \
218 obs->func; \ 213 obs->func; \
219 } \ 214 } \
220 } while (0) 215 } while (0)
221 216
222 #endif // BASE_OBSERVER_LIST_H__ 217 #endif // BASE_OBSERVER_LIST_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