Add STLDeleteValues, and use it.
This is the version from Chromium.
Change-Id: I5b7c6a544d5d5db8244869c58461cad16e7b4b86
diff --git a/src/jni_internal.cc b/src/jni_internal.cc
index 5ab8692..292d1e4 100644
--- a/src/jni_internal.cc
+++ b/src/jni_internal.cc
@@ -20,6 +20,7 @@
#include "object.h"
#include "runtime.h"
#include "scoped_jni_thread_state.h"
+#include "stl_util.h"
#include "stringpiece.h"
#include "thread.h"
@@ -555,10 +556,7 @@
}
~Libraries() {
- // Delete our map values. (The keys will be cleaned up by the map itself.)
- for (It it = libraries_.begin(); it != libraries_.end(); ++it) {
- delete it->second;
- }
+ STLDeleteValues(&libraries_);
}
SharedLibrary* Get(const std::string& path) {
diff --git a/src/stl_util.h b/src/stl_util.h
index 024f162..5fcf089 100644
--- a/src/stl_util.h
+++ b/src/stl_util.h
@@ -42,6 +42,18 @@
container->clear();
}
+// Given an STL container consisting of (key, value) pairs, STLDeleteValues
+// deletes all the "value" components and clears the container. Does nothing
+// in the case it's given a NULL pointer.
+template <class T>
+void STLDeleteValues(T *v) {
+ if (!v) return;
+ for (typename T::iterator i = v->begin(); i != v->end(); ++i) {
+ delete i->second;
+ }
+ v->clear();
+}
+
} // namespace art
#endif // ART_SRC_STL_UTIL_H_