From afed457be245a5b0ae6c88ad2ca0276691356279 Mon Sep 17 00:00:00 2001 From: "tfarina@chromium.org" Date: Thu, 9 Jun 2011 18:00:11 +0000 Subject: 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 --- views/view.cc | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'views/view.cc') 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()); - std::vector::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::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::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_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::const_iterator iter; - for (iter = accelerators_->begin() + registered_accelerator_count_; - iter != accelerators_->end(); ++iter) { - accelerator_focus_manager_->RegisterAccelerator(*iter, this); + for (std::vector::const_iterator i( + accelerators_->begin() + registered_accelerator_count_); + i != accelerators_->end(); ++i) { + accelerator_focus_manager_->RegisterAccelerator(*i, this); } registered_accelerator_count_ = accelerators_->size(); } -- cgit v1.1