0

Remove stl_util's STLDeleteContainerPointers.

BUG=555865

Review-Url: https://codereview.chromium.org/2457343002
Cr-Commit-Position: refs/heads/master@{#429152}
This commit is contained in:
avi
2016-11-01 16:29:43 -07:00
committed by Commit bot
parent 5a4155fcd8
commit 72d3b88b5e
3 changed files with 11 additions and 33 deletions

@ -314,15 +314,6 @@ _BANNED_CPP_FUNCTIONS = (
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
(

@ -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.

@ -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<
@ -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();
}
@ -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;