]> sourceware.org Git - systemtap.git/commitdiff
Simplify deleting all map values
authorJosh Stone <jistone@redhat.com>
Wed, 9 Sep 2009 23:13:16 +0000 (16:13 -0700)
committerJosh Stone <jistone@redhat.com>
Thu, 10 Sep 2009 20:20:36 +0000 (13:20 -0700)
* util.h (delete_map): New templated map deleter.
* dwflpp.cxx (dwflpp::~dwflpp): Use it.
* tapsets.cxx (symbol_table::~symbol_table): Use it.

dwflpp.cxx
tapsets.cxx
util.h

index d96f3eda9f79e3aaad2f336997fb5692c462d80c..36b016c7627c683592581d345cce9ee9361ecbb9 100644 (file)
@@ -98,25 +98,11 @@ dwflpp::~dwflpp()
 {
   free(cached_scopes);
 
-  for (module_cu_cache_t::iterator it = module_cu_cache.begin();
-       it != module_cu_cache.end(); ++it)
-    delete it->second;
-
-  for (mod_cu_function_cache_t::iterator it = cu_function_cache.begin();
-       it != cu_function_cache.end(); ++it)
-    delete it->second;
-
-  for (cu_inl_function_cache_t::iterator it = cu_inl_function_cache.begin();
-       it != cu_inl_function_cache.end(); ++it)
-    delete it->second;
-
-  for (mod_cu_type_cache_t::iterator it = global_alias_cache.begin();
-       it != global_alias_cache.end(); ++it)
-    delete it->second;
-
-  for (mod_cu_die_parent_cache_t::iterator it = cu_die_parent_cache.begin();
-       it != cu_die_parent_cache.end(); ++it)
-    delete it->second;
+  delete_map(module_cu_cache);
+  delete_map(cu_function_cache);
+  delete_map(cu_inl_function_cache);
+  delete_map(global_alias_cache);
+  delete_map(cu_die_parent_cache);
 
   if (dwfl)
     dwfl_end(dwfl);
index 346fa7f323f6ddbccc620008126ba55f4e936e31..fc8cb88bed642420eceafe6cc5a9c6bd2c92a438 100644 (file)
@@ -3820,8 +3820,7 @@ dwarf_builder::build(systemtap_session & sess,
 
 symbol_table::~symbol_table()
 {
-  for (iterator_t i = map_by_addr.begin(); i != map_by_addr.end(); ++i)
-    delete i->second;
+  delete_map(map_by_addr);
 }
 
 void
diff --git a/util.h b/util.h
index b38d01fdd290fd669cc3410d653821e1b1769e32..24845545991809c61b88c21068d2417a6aeaccf0 100644 (file)
--- a/util.h
+++ b/util.h
@@ -97,4 +97,16 @@ lex_cast_qstring(std::string const & in)
   return out;
 }
 
+
+// Delete all values from a map-like container and clear it
+// (The template is permissive -- be good!)
+template <typename T>
+void delete_map(T& t)
+{
+  for (typename T::iterator i = t.begin(); i != t.end(); ++i)
+    delete i->second;
+  t.clear();
+}
+
+
 /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */
This page took 0.051259 seconds and 5 git commands to generate.