From 2a5cab9b4471b4536c3576ec20cb2b6d6bc122e3 Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Fri, 15 Jun 2012 03:26:47 +0200 Subject: Use less memory when rehashing built-in hashmaps --- src/inspircd.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/inspircd.cpp b/src/inspircd.cpp index cf8c22633..aa03d62de 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -195,24 +195,21 @@ void InspIRCd::ResetMaxBans() void InspIRCd::RehashUsersAndChans() { user_hash* old_users = Users->clientlist; - user_hash* old_uuid = Users->uuidlist; - chan_hash* old_chans = chanlist; - - Users->clientlist = new user_hash(); - Users->uuidlist = new user_hash(); - chanlist = new chan_hash(); - + Users->clientlist = new user_hash; for (user_hash::const_iterator n = old_users->begin(); n != old_users->end(); n++) Users->clientlist->insert(*n); + delete old_users; + user_hash* old_uuid = Users->uuidlist; + Users->uuidlist = new user_hash; for (user_hash::const_iterator n = old_uuid->begin(); n != old_uuid->end(); n++) Users->uuidlist->insert(*n); + delete old_uuid; + chan_hash* old_chans = chanlist; + chanlist = new chan_hash; for (chan_hash::const_iterator n = old_chans->begin(); n != old_chans->end(); n++) chanlist->insert(*n); - - delete old_users; - delete old_uuid; delete old_chans; // Reset the already_sent IDs so we don't wrap it around and drop a message -- cgit v1.2.3