summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-11-05 19:52:16 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-11-05 19:52:16 +0000
commit91a3d1324b70945b52acb607470336c562280ff4 (patch)
treec5aeb8b6011c9477e88fe0a8b1158437993f3c45
parent477681996b164c8dacc930c3df378129a3bf929d (diff)
Rehash method added which frees unused memory from the hash_map. Has a delete-safe iterator. see comments.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8542 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/bancache.h2
-rw-r--r--src/bancache.cpp22
2 files changed, 24 insertions, 0 deletions
diff --git a/include/bancache.h b/include/bancache.h
index 19fc0d952..2ae740ece 100644
--- a/include/bancache.h
+++ b/include/bancache.h
@@ -62,6 +62,8 @@ class CoreExport BanCacheManager : public classbase
this->ServerInstance = Instance;
this->BanHash = new BanCacheHash();
}
+
+ void RehashCache();
};
#endif
diff --git a/src/bancache.cpp b/src/bancache.cpp
index a831b1219..bfa1bde11 100644
--- a/src/bancache.cpp
+++ b/src/bancache.cpp
@@ -63,4 +63,26 @@ bool BanCacheManager::RemoveHit(BanCacheHit *b)
return true;
}
+void BanCacheManager::RehashCache()
+{
+ BanCacheHash* NewHash = new BanCacheHash();
+
+ BanCacheHash::iterator safei;
+ for (BanCacheHash::iterator n = BanHash->begin(); n != BanHash->end(); )
+ {
+ safei = n;
+ safei++;
+
+ /* Safe to delete items here through iterator 'n' */
+
+ /* Actually inserts a std::pair */
+ NewHash->insert(*n);
+ /* End of safe section */
+
+ n = safei;
+ }
+
+ delete BanHash;
+ BanHash = NewHash;
+}