Skip to content

Commit

Permalink
Remove stl_util's STLDeleteContainerPointers.
Browse files Browse the repository at this point in the history
BUG=555865

Review-Url: https://codereview.chromium.org/2457343002
Cr-Commit-Position: refs/heads/master@{#429152}
  • Loading branch information
avi authored and Commit bot committed Nov 1, 2016
1 parent 5a4155f commit 72d3b88
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 33 deletions.
9 changes: 0 additions & 9 deletions PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::unique_ptr<x>> ).',
),
True,
(),
),
(
r'STLDeleteElements', # http://crbug.com/555865
(
Expand Down
6 changes: 3 additions & 3 deletions base/containers/scoped_ptr_hash_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 8 additions & 21 deletions base/stl_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class ForwardIterator>
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 Container, typename T>
typename std::iterator_traits<
Expand Down Expand Up @@ -85,7 +67,13 @@ template <class T>
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();
}

Expand All @@ -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;
Expand Down

0 comments on commit 72d3b88

Please sign in to comment.