diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-09 18:00:11 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-09 18:00:11 +0000 |
commit | afed457be245a5b0ae6c88ad2ca0276691356279 (patch) | |
tree | ba90adbacf3e2f88cacf25ee4abdc8a2dd30540c /views | |
parent | c8fc70d76a31bb9bccdb646423e172a0b963644b (diff) | |
download | chromium_src-afed457be245a5b0ae6c88ad2ca0276691356279.zip chromium_src-afed457be245a5b0ae6c88ad2ca0276691356279.tar.gz chromium_src-afed457be245a5b0ae6c88ad2ca0276691356279.tar.bz2 |
views: STL iterator cleanups in View class.
- Standardize iterator naming to |i|.
- Initialize them through constructor not assignment operator.
- Declare iterators inside loops, not above them.
BUG=72040
TEST=None
R=pkasting@chromium.org,sky@chromium.org
Review URL: http://codereview.chromium.org/7129028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88551 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/view.cc | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/views/view.cc b/views/view.cc index 85c5247..3c4183f 100644 --- a/views/view.cc +++ b/views/view.cc @@ -878,9 +878,8 @@ void View::AddAccelerator(const Accelerator& accelerator) { if (!accelerators_.get()) accelerators_.reset(new std::vector<Accelerator>()); - std::vector<Accelerator>::iterator iter = - std::find(accelerators_->begin(), accelerators_->end(), accelerator); - DCHECK(iter == accelerators_->end()) + DCHECK(std::find(accelerators_->begin(), accelerators_->end(), accelerator) == + accelerators_->end()) << "Registering the same accelerator multiple times"; accelerators_->push_back(accelerator); @@ -888,16 +887,20 @@ void View::AddAccelerator(const Accelerator& accelerator) { } void View::RemoveAccelerator(const Accelerator& accelerator) { - std::vector<Accelerator>::iterator iter; - if (!accelerators_.get() || - ((iter = std::find(accelerators_->begin(), accelerators_->end(), - accelerator)) == accelerators_->end())) { + if (!accelerators_.get()) { + NOTREACHED() << "Removing non-existing accelerator"; + return; + } + + std::vector<Accelerator>::iterator i( + std::find(accelerators_->begin(), accelerators_->end(), accelerator)); + if (i == accelerators_->end()) { NOTREACHED() << "Removing non-existing accelerator"; return; } - size_t index = iter - accelerators_->begin(); - accelerators_->erase(iter); + size_t index = i - accelerators_->begin(); + accelerators_->erase(i); if (index >= registered_accelerator_count_) { // The accelerator is not registered to FocusManager. return; @@ -1347,7 +1350,7 @@ void View::DoRemoveChildView(View* view, bool update_tool_tip, bool delete_removed_view) { DCHECK(view); - const Views::iterator i = std::find(children_.begin(), children_.end(), view); + const Views::iterator i(std::find(children_.begin(), children_.end(), view)); scoped_ptr<View> view_to_be_deleted; if (i != children_.end()) { if (update_focus_cycle) { @@ -1484,7 +1487,7 @@ void View::BoundsChanged(const gfx::Rect& previous_bounds) { // Notify interested Views that visible bounds within the root view may have // changed. if (descendants_to_notify_.get()) { - for (Views::iterator i = descendants_to_notify_->begin(); + for (Views::iterator i(descendants_to_notify_->begin()); i != descendants_to_notify_->end(); ++i) { (*i)->OnVisibleBoundsChanged(); } @@ -1539,9 +1542,8 @@ void View::AddDescendantToNotify(View* view) { void View::RemoveDescendantToNotify(View* view) { DCHECK(view && descendants_to_notify_.get()); - Views::iterator i = std::find(descendants_to_notify_->begin(), - descendants_to_notify_->end(), - view); + Views::iterator i(std::find( + descendants_to_notify_->begin(), descendants_to_notify_->end(), view)); DCHECK(i != descendants_to_notify_->end()); descendants_to_notify_->erase(i); if (descendants_to_notify_->empty()) @@ -1733,10 +1735,10 @@ void View::RegisterPendingAccelerators() { // Only register accelerators if we are visible. if (!IsVisibleInRootView()) return; - std::vector<Accelerator>::const_iterator iter; - for (iter = accelerators_->begin() + registered_accelerator_count_; - iter != accelerators_->end(); ++iter) { - accelerator_focus_manager_->RegisterAccelerator(*iter, this); + for (std::vector<Accelerator>::const_iterator i( + accelerators_->begin() + registered_accelerator_count_); + i != accelerators_->end(); ++i) { + accelerator_focus_manager_->RegisterAccelerator(*i, this); } registered_accelerator_count_ = accelerators_->size(); } |