summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-21 08:39:51 +0000
committerjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-21 08:39:51 +0000
commit8b7ddc7fa369ba9bb74d784cc13f3eda98361246 (patch)
treed3652b3a4bf40b59a4baa0f8d6813f17cfba06ff /base
parent987658716e32b12ec8e17973bbe4bc4e582e5112 (diff)
downloadchromium_src-8b7ddc7fa369ba9bb74d784cc13f3eda98361246.zip
chromium_src-8b7ddc7fa369ba9bb74d784cc13f3eda98361246.tar.gz
chromium_src-8b7ddc7fa369ba9bb74d784cc13f3eda98361246.tar.bz2
Small stl_util tidy up
Follow up to http://codereview.chromium.org/7342047/ - pull in some upstream changes - remove the non-portable vector_as_array micro-optimization. BUG=None TEST=All existing tests pass Review URL: http://codereview.chromium.org/7465001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93359 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/stl_util.h17
1 files changed, 5 insertions, 12 deletions
diff --git a/base/stl_util.h b/base/stl_util.h
index 299c595..af77150 100644
--- a/base/stl_util.h
+++ b/base/stl_util.h
@@ -8,9 +8,6 @@
#define BASE_STL_UTIL_H_
#pragma once
-#include <assert.h>
-#include <string.h> // for memcpy
-
#include <string>
#include <vector>
@@ -79,13 +76,17 @@ void STLDeleteContainerPairFirstPointers(ForwardIterator begin,
// STLDeleteContainerPairSecondPointers()
// For a range within a container of pairs, calls delete
+// 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.
// (non-array version) on the SECOND item in the pairs.
template <class ForwardIterator>
void STLDeleteContainerPairSecondPointers(ForwardIterator begin,
ForwardIterator end) {
while (begin != end) {
- delete begin->second;
+ ForwardIterator temp = begin;
++begin;
+ delete temp->second;
}
}
@@ -95,20 +96,12 @@ void STLDeleteContainerPairSecondPointers(ForwardIterator begin,
template<typename T>
inline T* vector_as_array(std::vector<T>* v) {
-# ifdef NDEBUG
- return &*v->begin();
-# else
return v->empty() ? NULL : &*v->begin();
-# endif
}
template<typename T>
inline const T* vector_as_array(const std::vector<T>* v) {
-# ifdef NDEBUG
- return &*v->begin();
-# else
return v->empty() ? NULL : &*v->begin();
-# endif
}
// Return a mutable char* pointing to a string's internal buffer,