soc.2009.transport: 323ea452: Std::map in UserManager replaced by GHas...
hanzz at soc.pidgin.im
hanzz at soc.pidgin.im
Sat May 2 05:25:34 EDT 2009
-----------------------------------------------------------------
Revision: 323ea452dd045d5455a58dc76f8b7b4dc447d507
Ancestor: 105c34fd19ed79e33a12268e536d08ec2fe2ff4d
Author: hanzz at soc.pidgin.im
Date: 2009-05-02T09:23:45
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/323ea452dd045d5455a58dc76f8b7b4dc447d507
Modified files:
usermanager.cpp usermanager.h
ChangeLog:
Std::map in UserManager replaced by GHashTable because of better performance (we don't need to sort users).
-------------- next part --------------
============================================================
--- usermanager.cpp 6e82743d6eef5d00923184b5dd3cd0212a261b9b
+++ usermanager.cpp 08b6d92c812d26faae81beb3fbcf4b3c05ecc266
@@ -32,6 +32,7 @@ UserManager::UserManager(GlooxMessageHan
UserManager::UserManager(GlooxMessageHandler *m){
main = m;
+ m_users = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
}
UserManager::~UserManager(){
@@ -39,10 +40,7 @@ User *UserManager::getUserByJID(std::str
}
User *UserManager::getUserByJID(std::string barejid){
- User *user = NULL;
- std::map<std::string,User*>::iterator it = m_users.find(barejid);
- if (it != m_users.end())
- user = (*it).second;
+ User *user = (User*) g_hash_table_lookup(m_users, user->jid().c_str());
return user;
}
@@ -54,14 +52,14 @@ void UserManager::removeUser(User *user)
void UserManager::removeUser(User *user){
Log().Get("logout") << "removing user";
- m_users.erase(user->jid());
+ g_hash_table_remove(m_users, user->jid().c_str());
delete user;
Log().Get("logout") << "delete user; called => user is sucesfully removed";
}
void UserManager::removeUserTimer(User *user){
Log().Get("logout") << "removing user by timer";
- m_users.erase(user->jid());
+ g_hash_table_remove(m_users, user->jid().c_str());
// this will be called by gloop after all
g_timeout_add(0,&deleteUser,user);
}
============================================================
--- usermanager.h edc2f11c75a806e475cff2df2d9dfed9708b2eaa
+++ usermanager.h 14f366c66f12a882b48d6701e45bcbcb54a15bfa
@@ -22,9 +22,9 @@
#define USERMANAGER_H
#include <string>
-#include <map>
#include "account.h"
#include "user.h"
+#include "glib.h"
class GlooxMessageHandler;
@@ -35,17 +35,17 @@ class UserManager
~UserManager();
User *getUserByJID(std::string barejid);
User *getUserByAccount(PurpleAccount *account);
- void addUser(User *user) { m_users[user->jid()] = user; }
+ void addUser(User *user) { g_hash_table_replace(m_users, g_strdup(user->jid().c_str()), user); }
void removeUser(User *user);
void removeUserTimer(User *user);
void buddyOnline();
void buddyOffline();
long onlineUserCount();
- int userCount() { return m_users.size(); }
+ int userCount() { return g_hash_table_size(m_users); }
private:
GlooxMessageHandler *main;
- std::map<std::string, User*> m_users;
+ GHashTable *m_users; // key = JID; value = User*
long m_onlineBuddies;
};
More information about the Commits
mailing list