soc.2009.transport: ff1f3f97: Better performance of UserManager::getUs...

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Fri Jun 12 06:15:36 EDT 2009


-----------------------------------------------------------------
Revision: ff1f3f978924715dac0995371901fd3a692dbdb7
Ancestor: 4607ce3e7276f9455f02a48603a7ed50aee88986
Author: hanzz at soc.pidgin.im
Date: 2009-06-12T10:11:19
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/ff1f3f978924715dac0995371901fd3a692dbdb7

Modified files:
        usermanager.cpp usermanager.h

ChangeLog: 

Better performance of UserManager::getUserBy*

-------------- next part --------------
============================================================
--- usermanager.cpp	2827384bdcc8da87746de013a569e0ab857ae3c6
+++ usermanager.cpp	a4c6f22a6dd5f711996f393413dc2a2908bc36f2
@@ -33,6 +33,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);
+	m_cachedUser = NULL;
 }
 
 UserManager::~UserManager(){
@@ -40,7 +41,11 @@ User *UserManager::getUserByJID(std::str
 }
 
 User *UserManager::getUserByJID(std::string barejid){
+	if (m_cachedUser && barejid == m_cachedUser->jid()) {
+		return m_cachedUser;
+	}
 	User *user = (User*) g_hash_table_lookup(m_users, barejid.c_str());
+	m_cachedUser = user;
 	return user;
 }
 
@@ -53,6 +58,9 @@ void UserManager::removeUser(User *user)
 void UserManager::removeUser(User *user){
 	Log().Get("logout") << "removing user";
 	g_hash_table_remove(m_users, user->jid().c_str());
+	if (m_cachedUser && user->jid() == m_cachedUser->jid()) {
+		m_cachedUser = NULL;
+	}
 	delete user;
 	Log().Get("logout") << "delete user; called => user is sucesfully removed";
 }
@@ -60,6 +68,9 @@ void UserManager::removeUserTimer(User *
 void UserManager::removeUserTimer(User *user){
 	Log().Get("logout") << "removing user by timer";
 	g_hash_table_remove(m_users, user->jid().c_str());
+	if (m_cachedUser && user->jid() == m_cachedUser->jid()) {
+		m_cachedUser = NULL;
+	}
 	// this will be called by gloop after all
 	g_timeout_add(0,&deleteUser,user);
 }
============================================================
--- usermanager.h	14f366c66f12a882b48d6701e45bcbcb54a15bfa
+++ usermanager.h	ec329deda93f3d3d451bf9ce02429c71b5cc6b4b
@@ -47,6 +47,7 @@ class UserManager
 		GlooxMessageHandler *main;
 		GHashTable *m_users;	// key = JID; value = User*
 		long m_onlineBuddies;
+		User *m_cachedUser;
 	
 };
 


More information about the Commits mailing list