From 72d3b88b5e27a7ad7cd2baf421e8432d15a510a3 Mon Sep 17 00:00:00 2001 From: avi Date: Tue, 1 Nov 2016 16:29:43 -0700 Subject: [PATCH] Remove stl_util's STLDeleteContainerPointers. BUG=555865 Review-Url: https://codereview.chromium.org/2457343002 Cr-Commit-Position: refs/heads/master@{#429152} --- PRESUBMIT.py | 9 --------- base/containers/scoped_ptr_hash_map.h | 6 +++--- base/stl_util.h | 29 ++++++++------------------- 3 files changed, 11 insertions(+), 33 deletions(-) diff --git a/PRESUBMIT.py b/PRESUBMIT.py index cc13d4188b8029..655d7b871e81cc 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -314,15 +314,6 @@ True, (), ), - ( - r'STLDeleteContainerPointers', # http://crbug.com/555865 - ( - 'This call is obsolete with C++ 11; create a container with owning', - 'pointers instead (e.g. std::vector> ).', - ), - True, - (), - ), ( r'STLDeleteElements', # http://crbug.com/555865 ( diff --git a/base/containers/scoped_ptr_hash_map.h b/base/containers/scoped_ptr_hash_map.h index 03f25c5b637199..72c6ff4152e2d0 100644 --- a/base/containers/scoped_ptr_hash_map.h +++ b/base/containers/scoped_ptr_hash_map.h @@ -128,9 +128,9 @@ class ScopedPtrHashMap { inline void clear() { auto it = data_.begin(); while (it != data_.end()) { - // NOTE: Like STLDeleteContainerPointers, deleting behind the iterator. - // Deleting the value does not always invalidate the iterator, but it may - // do so if the key is a pointer into the value object. + // NOTE: Deleting behind the iterator. Deleting the value does not always + // invalidate the iterator, but it may do so if the key is a pointer into + // the value object. auto temp = it; ++it; // Let ScopedPtr decide how to delete. diff --git a/base/stl_util.h b/base/stl_util.h index 4159d8524a3f7e..3f7555dde54500 100644 --- a/base/stl_util.h +++ b/base/stl_util.h @@ -29,24 +29,6 @@ void STLClearObject(T* obj) { obj->reserve(0); } -// For a range within a container of pointers, calls delete (non-array version) -// on these pointers. -// NOTE: for these three functions, we could just implement a DeleteObject -// functor and then call for_each() on the range and functor, but this -// requires us to pull in all of algorithm.h, which seems expensive. -// For hash_[multi]set, it is important that this deletes behind the iterator -// because the hash_set may call the hash function on the iterator when it is -// advanced, which could result in the hash function trying to deference a -// stale pointer. -template -void STLDeleteContainerPointers(ForwardIterator begin, ForwardIterator end) { - while (begin != end) { - ForwardIterator temp = begin; - ++begin; - delete *temp; - } -} - // Counts the number of instances of val in a container. template typename std::iterator_traits< @@ -85,7 +67,13 @@ template void STLDeleteElements(T* container) { if (!container) return; - STLDeleteContainerPointers(container->begin(), container->end()); + + for (auto it = container->begin(); it != container->end();) { + auto temp = it; + ++it; + delete *temp; + } + container->clear(); } @@ -97,8 +85,7 @@ void STLDeleteValues(T* container) { if (!container) return; - auto it = container->begin(); - while (it != container->end()) { + for (auto it = container->begin(); it != container->end();) { auto temp = it; ++it; delete temp->second;