Mercurial > pidgin.yaz
diff libpurple/protocols/msn/user.c @ 29350:99d1b433dba0
Keep CurrentMedia in a separate object outside of MsnUser that needs to
be allocated if a user has media. This makes MsnUser smaller by the
size of 3 pointers (apparently) for each buddy in your buddy list.
In practice it looks like less than 1% of MSN users have media set,
so this should save a little bit of memory.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 04 Feb 2010 00:15:41 +0000 |
parents | d213c8ad89da |
children | 08296b862f98 |
line wrap: on
line diff
--- a/libpurple/protocols/msn/user.c Wed Feb 03 22:48:03 2010 +0000 +++ b/libpurple/protocols/msn/user.c Thu Feb 04 00:15:41 2010 +0000 @@ -70,9 +70,12 @@ g_free(user->phone.home); g_free(user->phone.work); g_free(user->phone.mobile); - g_free(user->media.artist); - g_free(user->media.title); - g_free(user->media.album); + if (user->media) { + g_free(user->media->artist); + g_free(user->media->title); + g_free(user->media->album); + g_free(user->media); + } g_free(user->statusline); g_free(user->invite_message); @@ -107,24 +110,24 @@ purple_prpl_got_user_status_deactive(account, user->passport, "mobile"); } - if (!offline && user->media.type != CURRENT_MEDIA_UNKNOWN) { - if (user->media.type == CURRENT_MEDIA_MUSIC) { + if (!offline && user->media && user->media->type != CURRENT_MEDIA_UNKNOWN) { + if (user->media->type == CURRENT_MEDIA_MUSIC) { purple_prpl_got_user_status(account, user->passport, "tune", - PURPLE_TUNE_ARTIST, user->media.artist, - PURPLE_TUNE_ALBUM, user->media.album, - PURPLE_TUNE_TITLE, user->media.title, + PURPLE_TUNE_ARTIST, user->media->artist, + PURPLE_TUNE_ALBUM, user->media->album, + PURPLE_TUNE_TITLE, user->media->title, NULL); - } else if (user->media.type == CURRENT_MEDIA_GAMES) { + } else if (user->media->type == CURRENT_MEDIA_GAMES) { purple_prpl_got_user_status(account, user->passport, "tune", - "game", user->media.title, + "game", user->media->title, NULL); - } else if (user->media.type == CURRENT_MEDIA_OFFICE) { + } else if (user->media->type == CURRENT_MEDIA_OFFICE) { purple_prpl_got_user_status(account, user->passport, "tune", - "office", user->media.title, + "office", user->media->title, NULL); } else { purple_debug_warning("msn", "Got CurrentMedia with unknown type %d.\n", - user->media.type); + user->media->type); } } else { purple_prpl_got_user_status_deactive(account, user->passport, "tune"); @@ -205,18 +208,16 @@ } void -msn_user_set_currentmedia(MsnUser *user, const CurrentMedia *media) +msn_user_set_currentmedia(MsnUser *user, CurrentMedia *media) { - g_return_if_fail(user != NULL); + if (user->media) { + g_free(user->media->title); + g_free(user->media->album); + g_free(user->media->artist); + g_free(user->media); + } - g_free(user->media.title); - g_free(user->media.album); - g_free(user->media.artist); - - user->media.type = media ? media->type : CURRENT_MEDIA_UNKNOWN; - user->media.title = media ? g_strdup(media->title) : NULL; - user->media.artist = media ? g_strdup(media->artist) : NULL; - user->media.album = media ? g_strdup(media->album) : NULL; + user->media = media; } void