diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2009-10-23 18:09:22 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2009-10-23 18:09:22 +0200 |
commit | 5d8561e4257f13756010daca1bb098bdef9cb97c (patch) | |
tree | 6c6b9e95af4b66839d696a050c392d46775cf1dc | |
parent | 4b3d1128bf96b96322e4b99da4633f44fa49e585 (diff) |
Store a pointer to the correct user (user->real_user) for users with mapped nicks to avoid looking up the nick on every call to user_get().
-rw-r--r-- | user.c | 7 | ||||
-rw-r--r-- | user.h | 4 |
2 files changed, 6 insertions, 5 deletions
@@ -12,8 +12,7 @@ void user_init() { memset(users, 0, sizeof(struct user_t) * USERS_MAX); } -struct user_t *user_get(char *_nick) { - char *nick = nick_get(_nick); +struct user_t *user_get(char *nick) { unsigned long hash = sdbm(nick); int index = hash % USERS_MAX; @@ -35,9 +34,11 @@ struct user_t *user_get(char *_nick) { memset(user->lines, 0, 24*4 * sizeof(unsigned long)); user->words = user->characters = user->kicks = user->kicked = 0; user->next = NULL; + char *_nick = nick_get(nick); + user->real_user = strcmp(nick, _nick) ? user_get(_nick) : NULL; } - return user; + return (user->real_user ? user->real_user : user); } void user_free() { @@ -8,11 +8,11 @@ struct user_t { char *nick; unsigned long lines[24*4]; unsigned long long words, characters, kicks, kicked; - struct user_t *next; + struct user_t *real_user, *next; }; void user_init(); -struct user_t *user_get(char *_nick); +struct user_t *user_get(char *nick); void user_free(); extern struct user_t *users; |