Chromium Code Reviews| Index: ui/views/focus/view_storage.cc |
| diff --git a/ui/views/focus/view_storage.cc b/ui/views/focus/view_storage.cc |
| index 371e2d1a8ee72ff3551bbdece7ae5d4efe47d1d2..4c519f3f8cb9b4e08b44d55639ef4f5b29be6a84 100644 |
| --- a/ui/views/focus/view_storage.cc |
| +++ b/ui/views/focus/view_storage.cc |
| @@ -8,7 +8,6 @@ |
| #include "base/logging.h" |
| #include "base/memory/singleton.h" |
| -#include "base/stl_util.h" |
| namespace views { |
| @@ -20,10 +19,7 @@ ViewStorage* ViewStorage::GetInstance() { |
| ViewStorage::ViewStorage() : view_storage_next_id_(0) { |
| } |
| -ViewStorage::~ViewStorage() { |
| - base::STLDeleteContainerPairSecondPointers(view_to_ids_.begin(), |
| - view_to_ids_.end()); |
| -} |
| +ViewStorage::~ViewStorage() {} |
| int ViewStorage::CreateStorageID() { |
| return view_storage_next_id_++; |
| @@ -31,31 +27,20 @@ int ViewStorage::CreateStorageID() { |
| void ViewStorage::StoreView(int storage_id, View* view) { |
| DCHECK(view); |
| - std::map<int, View*>::iterator iter = id_to_view_.find(storage_id); |
| - if (iter != id_to_view_.end()) { |
| + if (id_to_view_.find(storage_id) != id_to_view_.end()) { |
| NOTREACHED(); |
| RemoveView(storage_id); |
| } |
| id_to_view_[storage_id] = view; |
| - |
| - std::vector<int>* ids = NULL; |
| - std::map<View*, std::vector<int>*>::iterator id_iter = |
| - view_to_ids_.find(view); |
| - if (id_iter == view_to_ids_.end()) { |
| - ids = new std::vector<int>(); |
| - view_to_ids_[view] = ids; |
| - } else { |
| - ids = id_iter->second; |
| - } |
| - ids->push_back(storage_id); |
| + view_to_ids_[view].push_back(storage_id); |
| } |
| View* ViewStorage::RetrieveView(int storage_id) { |
| - std::map<int, View*>::iterator iter = id_to_view_.find(storage_id); |
| + auto iter = id_to_view_.find(storage_id); |
| if (iter == id_to_view_.end()) |
| - return NULL; |
| + return nullptr; |
| return iter->second; |
| } |
| @@ -65,22 +50,21 @@ void ViewStorage::RemoveView(int storage_id) { |
| void ViewStorage::ViewRemoved(View* removed) { |
| // Let's first retrieve the ids for that view. |
| - std::map<View*, std::vector<int>*>::iterator ids_iter = |
| - view_to_ids_.find(removed); |
| + auto ids_iter = view_to_ids_.find(removed); |
| if (ids_iter == view_to_ids_.end()) { |
| // That view is not in the view storage. |
| return; |
| } |
| - std::vector<int>* ids = ids_iter->second; |
| - DCHECK(!ids->empty()); |
| - EraseView((*ids)[0], true); |
| + const std::vector<int>& ids = ids_iter->second; |
| + DCHECK(!ids.empty()); |
| + EraseView(ids[0], true); |
| } |
| void ViewStorage::EraseView(int storage_id, bool remove_all_ids) { |
| // Remove the view from id_to_view_location_. |
| - std::map<int, View*>::iterator view_iter = id_to_view_.find(storage_id); |
| + auto view_iter = id_to_view_.find(storage_id); |
| if (view_iter == id_to_view_.end()) |
| return; |
| @@ -88,28 +72,20 @@ void ViewStorage::EraseView(int storage_id, bool remove_all_ids) { |
| id_to_view_.erase(view_iter); |
| // Also update view_to_ids_. |
| - std::map<View*, std::vector<int>*>::iterator ids_iter = |
| - view_to_ids_.find(view); |
| + auto ids_iter = view_to_ids_.find(view); |
| DCHECK(ids_iter != view_to_ids_.end()); |
| - std::vector<int>* ids = ids_iter->second; |
| + std::vector<int>& ids = ids_iter->second; |
| if (remove_all_ids) { |
| - for (size_t i = 0; i < ids->size(); ++i) { |
| - view_iter = id_to_view_.find((*ids)[i]); |
| - if (view_iter != id_to_view_.end()) |
| - id_to_view_.erase(view_iter); |
| - } |
| - ids->clear(); |
| - } else { |
| - std::vector<int>::iterator id_iter = |
| - std::find(ids->begin(), ids->end(), storage_id); |
| - DCHECK(id_iter != ids->end()); |
| - ids->erase(id_iter); |
| - } |
| - |
| - if (ids->empty()) { |
| - delete ids; |
| + for (int id : ids) |
| + id_to_view_.erase(id); |
| view_to_ids_.erase(ids_iter); |
| + } else if (ids.size() == 1) { |
|
Nico
2016/09/19 17:32:30
pulling this out took me longer to read than the r
|
| + view_to_ids_.erase(ids_iter); |
| + } else { |
| + auto id_iter = std::find(ids.begin(), ids.end(), storage_id); |
| + DCHECK(id_iter != ids.end()); |
| + ids.erase(id_iter); |
| } |
| } |