Change O(n^2) loop to O(n) in ObserverListBase::Compact().

BUG=none
TEST=Time a short program having two versions of that code.

Review URL: http://codereview.chromium.org/8391003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107153 0039d316-1c4b-4281-b951-d872f2087c98
parent 7cc6e563
...@@ -162,14 +162,9 @@ class ObserverListBase ...@@ -162,14 +162,9 @@ class ObserverListBase
protected: protected:
void Compact() { void Compact() {
typename ListType::iterator it = observers_.begin(); observers_.erase(
while (it != observers_.end()) { std::remove(observers_.begin(), observers_.end(),
if (*it) { static_cast<ObserverType*>(NULL)), observers_.end());
++it;
} else {
it = observers_.erase(it);
}
}
} }
private: private:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment