pidgin: 4cc0bbe9: The other day while struct hiding, I not...
rlaager at pidgin.im
rlaager at pidgin.im
Thu Nov 27 15:40:49 EST 2008
-----------------------------------------------------------------
Revision: 4cc0bbe98be861a279e3b1fd97a3b4d491dec519
Ancestor: 0971ac0075b04d5ffec3c010a840aa243a9de01f
Author: rlaager at pidgin.im
Date: 2008-11-27T05:54:09
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/4cc0bbe98be861a279e3b1fd97a3b4d491dec519
Modified files:
finch/libgnt/gnttextview.c finch/libgnt/gntwm.c
libpurple/protocols/jabber/buddy.c
libpurple/protocols/jabber/si.c
libpurple/protocols/myspace/message.c
libpurple/protocols/sametime/sametime.c
libpurple/protocols/yahoo/yahoochat.c libpurple/request.c
pidgin/gtkblist.c pidgin/gtknotify.c pidgin/gtkrequest.c
pidgin/gtksavedstatuses.c pidgin/plugins/history.c
ChangeLog:
The other day while struct hiding, I noticed a for loop that was checking
g_list_length() as the loop conditional. I decided to check all our calls
to g_list_length() to see which ones I could clean up without too much work.
-------------- next part --------------
============================================================
--- finch/libgnt/gnttextview.c 53b8843c68b389556e8ea39ff8bebd3496ec7467
+++ finch/libgnt/gnttextview.c 9836c0bbe3e9a826df5176b8ae95a83db742f021
@@ -67,6 +67,7 @@ gnt_text_view_draw(GntWidget *widget)
gnt_text_view_draw(GntWidget *widget)
{
GntTextView *view = GNT_TEXT_VIEW(widget);
+ int n;
int i = 0;
GList *lines;
int rows, scrcol;
@@ -76,10 +77,11 @@ gnt_text_view_draw(GntWidget *widget)
wbkgd(widget->window, gnt_color_pair(GNT_COLOR_NORMAL));
werase(widget->window);
+ n = g_list_length(view->list);
if ((view->flags & GNT_TEXT_VIEW_TOP_ALIGN) &&
- g_list_length(view->list) < widget->priv.height) {
+ n < widget->priv.height) {
GList *now = view->list;
- comp = widget->priv.height - g_list_length(view->list);
+ comp = widget->priv.height - n;
view->list = g_list_nth_prev(view->list, comp);
if (!view->list) {
view->list = g_list_first(now);
@@ -236,6 +238,7 @@ gnt_text_view_get_p(GntTextView *view, i
static char *
gnt_text_view_get_p(GntTextView *view, int x, int y)
{
+ int n;
int i = 0;
GntWidget *wid = GNT_WIDGET(view);
GntTextLine *line;
@@ -244,10 +247,11 @@ gnt_text_view_get_p(GntTextView *view, i
GntTextSegment *seg;
gchar *pos;
+ n = g_list_length(view->list);
y = wid->priv.height - y;
- if (g_list_length(view->list) < y) {
+ if (n < y) {
x = 0;
- y = g_list_length(view->list) - 1;
+ y = n - 1;
}
lines = g_list_nth(view->list, y - 1);
============================================================
--- finch/libgnt/gntwm.c d1131470cc7fce659971dd2fa70ca80b8ed0a29f
+++ finch/libgnt/gntwm.c 29e44df1a64425e6c564cd3b33ca0b57ccca3631
@@ -201,7 +201,7 @@ update_act_msg(void)
GString *text = g_string_new("act: ");
if (message)
gnt_widget_destroy(message);
- if (g_list_length(act) == 0)
+ if (!act)
return;
for (iter = act; iter; iter = iter->next) {
GntWS *ws = iter->data;
@@ -927,6 +927,7 @@ list_actions(GntBindable *bindable, GLis
GntWidget *tree, *win;
GList *iter;
GntWM *wm = GNT_WM(bindable);
+ int n;
if (wm->_list.window || wm->menu)
return TRUE;
@@ -950,8 +951,9 @@ list_actions(GntBindable *bindable, GLis
gnt_tree_create_row(GNT_TREE(tree), action->label), NULL);
}
g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(action_list_activate), wm);
- gnt_widget_set_size(tree, 0, g_list_length(wm->acts));
- gnt_widget_set_position(win, 0, getmaxy(stdscr) - 3 - g_list_length(wm->acts));
+ n = g_list_length(wm->acts);
+ gnt_widget_set_size(tree, 0, n);
+ gnt_widget_set_position(win, 0, getmaxy(stdscr) - 3 - n);
gnt_widget_show(win);
return TRUE;
============================================================
--- libpurple/protocols/jabber/buddy.c b687d1cce701f26584534067479bb48e29893101
+++ libpurple/protocols/jabber/buddy.c 2953a9caa125959837fb444f38242552731fdc6d
@@ -966,7 +966,7 @@ static void jabber_buddy_info_show_if_re
}
#endif
} else {
- gboolean multiple_resources = jbi->jb->resources && (g_list_length(jbi->jb->resources) > 1);
+ gboolean multiple_resources = jbi->jb->resources && jbi->jb->resources->next;
for(resources = jbi->jb->resources; resources; resources = resources->next) {
char *purdy = NULL;
============================================================
--- libpurple/protocols/jabber/si.c cba5a5c9d56a2e36458e60129b0218969c67669c
+++ libpurple/protocols/jabber/si.c fe72d83ab5a71b250c2726d7016a5eed4455ba95
@@ -1085,7 +1085,7 @@ static void jabber_si_xfer_init(PurpleXf
purple_notify_error(jsx->js->gc, _("File Send Failed"), _("File Send Failed"), msg);
g_free(msg);
- } else if(g_list_length(jb->resources) == 1) {
+ } else if(!jb->resources->next) {
/* only 1 resource online (probably our most common case)
* so no need to ask who to send to */
jbr = jb->resources->data;
============================================================
--- libpurple/protocols/myspace/message.c 0301692093540b5cf62838387312b46bb836480f
+++ libpurple/protocols/myspace/message.c d5e139047a084dd3a7045ee46090a9350b78ef6d
@@ -613,6 +613,7 @@ msim_msg_pack_using(MsimMessage *msg,
const gchar *sep,
const gchar *begin, const gchar *end)
{
+ int num_items;
gchar **strings;
gchar **strings_tmp;
gchar *joined;
@@ -621,8 +622,10 @@ msim_msg_pack_using(MsimMessage *msg,
g_return_val_if_fail(msg != NULL, NULL);
+ num_items = g_list_length(msg);
+
/* Add one for NULL terminator for g_strjoinv(). */
- strings = (gchar **)g_new0(gchar *, g_list_length(msg) + 1);
+ strings = (gchar **)g_new0(gchar *, num_items + 1);
strings_tmp = strings;
g_list_foreach(msg, gf, &strings_tmp);
@@ -632,7 +635,7 @@ msim_msg_pack_using(MsimMessage *msg,
g_free(joined);
/* Clean up. */
- for (i = 0; i < g_list_length(msg); ++i) {
+ for (i = 0; i < num_items; ++i) {
g_free(strings[i]);
}
============================================================
--- libpurple/protocols/sametime/sametime.c 164bb32167add8d625cb0ec4757cca873a4bb1ab
+++ libpurple/protocols/sametime/sametime.c a0f247d667566e0e68cf5b76be64b0d2f80a30ec
@@ -4415,7 +4415,7 @@ static void add_buddy_resolved(struct mw
res = results->data;
if(!code && res && res->matches) {
- if(g_list_length(res->matches) == 1) {
+ if(!res->matches->next) {
struct mwResolveMatch *match = res->matches->data;
/* only one? that might be the right one! */
============================================================
--- libpurple/protocols/yahoo/yahoochat.c 4196414d981c3f3ae81170143fb1a099a76c84f1
+++ libpurple/protocols/yahoo/yahoochat.c 35a6293f4e27f3f1a809f5d35dcffd1e57bab68b
@@ -513,12 +513,12 @@ void yahoo_process_chat_join(PurpleConne
c = purple_find_chat(gc, YAHOO_CHAT_ID);
- if (room && (!c || purple_conv_chat_has_left(PURPLE_CONV_CHAT(c))) && members &&
- ((g_list_length(members) > 1) ||
+ if (room && (!c || purple_conv_chat_has_left(PURPLE_CONV_CHAT(c))) &&
+ members && (members->next ||
!g_ascii_strcasecmp(members->data, purple_connection_get_display_name(gc)))) {
- int i;
+ GList *l;
GList *flags = NULL;
- for (i = 0; i < g_list_length(members); i++)
+ for (l = members; l; l = l->next)
flags = g_list_append(flags, GINT_TO_POINTER(PURPLE_CBFLAGS_NONE));
if (c && purple_conv_chat_has_left(PURPLE_CONV_CHAT(c))) {
/* this might be a hack, but oh well, it should nicely */
============================================================
--- libpurple/request.c e86343376dc7ccb6922a25824ebdf02897f82bde
+++ libpurple/request.c 19d5388aa9b9c0bf61620968593d312e2a544c1b
@@ -887,7 +887,7 @@ purple_request_field_list_set_selected(P
purple_request_field_list_clear_selected(field);
if (!purple_request_field_list_get_multi_select(field) &&
- g_list_length(items) > 1)
+ items && items->next)
{
purple_debug_warning("request",
"More than one item added to non-multi-select "
============================================================
--- pidgin/gtkblist.c 031e200e2e9534d8053c775c13843e2f5c3ae591
+++ pidgin/gtkblist.c 9705d34cddb465d11c8fbc646906741c4779628a
@@ -3320,6 +3320,7 @@ static char *pidgin_get_tooltip_text(Pur
if (PURPLE_BLIST_NODE_IS_CHAT(node))
{
PurpleChat *chat;
+ GList *connections;
GList *cur;
struct proto_chat_entry *pce;
char *name, *value;
@@ -3330,7 +3331,8 @@ static char *pidgin_get_tooltip_text(Pur
prpl = purple_find_prpl(purple_account_get_protocol_id(chat->account));
prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
- if (g_list_length(purple_connections_get_all()) > 1)
+ connections = purple_connections_get_all();
+ if (connections && connections->next)
{
tmp = g_markup_escape_text(chat->account->username, -1);
g_string_append_printf(str, _("<b>Account:</b> %s"), tmp);
@@ -3400,6 +3402,7 @@ static char *pidgin_get_tooltip_text(Pur
PurpleBuddy *b;
PurplePresence *presence;
PurpleNotifyUserInfo *user_info;
+ GList *connections;
char *tmp;
time_t idle_secs, signon;
@@ -3421,7 +3424,8 @@ static char *pidgin_get_tooltip_text(Pur
user_info = purple_notify_user_info_new();
/* Account */
- if (full && g_list_length(purple_connections_get_all()) > 1)
+ connections = purple_connections_get_all();
+ if (full && connections && connections->next)
{
tmp = g_markup_escape_text(purple_account_get_username(
purple_buddy_get_account(b)), -1);
============================================================
--- pidgin/gtknotify.c bcea1126b9f82f78d2c5dd70ff0f1f3b5547b267
+++ pidgin/gtknotify.c 5feb0186ff12622b047d5258bccd3e45c3955245
@@ -730,7 +730,6 @@ pidgin_notify_searchresults_new_rows(Pur
GtkListStore *model = data->model;
GtkTreeIter iter;
GdkPixbuf *pixbuf;
- guint col_num;
GList *row, *column;
guint n;
@@ -738,9 +737,6 @@ pidgin_notify_searchresults_new_rows(Pur
pixbuf = pidgin_create_prpl_icon(purple_connection_get_account(gc), 0.5);
- /* +1 is for the automagically created Status column. */
- col_num = g_list_length(results->columns) + 1;
-
for (row = results->rows; row != NULL; row = row->next) {
gtk_list_store_append(model, &iter);
@@ -776,6 +772,7 @@ pidgin_notify_searchresults(PurpleConnec
guint col_num;
GList *columniter;
guint i;
+ GList *l;
GtkWidget *vbox;
GtkWidget *label;
@@ -869,8 +866,8 @@ pidgin_notify_searchresults(PurpleConnec
i++;
}
- for (i = 0; i < g_list_length(results->buttons); i++) {
- PurpleNotifySearchButton *b = g_list_nth_data(results->buttons, i);
+ for (l = results->buttons; l; l = l->next) {
+ PurpleNotifySearchButton *b = l->data;
GtkWidget *button = NULL;
switch (b->type) {
case PURPLE_NOTIFY_BUTTON_LABELED:
============================================================
--- pidgin/gtkrequest.c 1042456ad81552b5eca35413c526a8136185cb9f
+++ pidgin/gtkrequest.c d819c891448975f13a63e6658b70a2316e493359
@@ -853,12 +853,11 @@ create_choice_field(PurpleRequestField *
create_choice_field(PurpleRequestField *field)
{
GtkWidget *widget;
- GList *labels;
+ GList *labels = purple_request_field_choice_get_labels(field);
+ int num_labels = g_list_length(labels);
GList *l;
- labels = purple_request_field_choice_get_labels(field);
-
- if (g_list_length(labels) > 5)
+ if (num_labels > 5)
{
GtkWidget *menu;
GtkWidget *item;
@@ -892,7 +891,7 @@ create_choice_field(PurpleRequestField *
GtkWidget *radio;
gint i;
- if (g_list_length(labels) == 2)
+ if (num_labels == 2)
box = gtk_hbox_new(FALSE, PIDGIN_HIG_BOX_SPACE);
else
box = gtk_vbox_new(FALSE, 0);
============================================================
--- pidgin/gtksavedstatuses.c cb238e46e88a621480e4da34786fcc400ef65a57
+++ pidgin/gtksavedstatuses.c e1925c4c1cd66396bc13a490ecf7c7e75cfd4f77
@@ -331,7 +331,8 @@ status_window_delete_cb(GtkButton *butto
}
g_list_free(sel_paths);
- if (g_list_length(sel_titles) == 1) {
+ g_return_if_fail(sel_titles != NULL);
+ if (!sel_titles->next) {
title = g_strdup_printf(_("Are you sure you want to delete %s?"),
(const gchar *)sel_titles->data);
handle = purple_savedstatus_find(sel_titles->data);
============================================================
--- pidgin/plugins/history.c 19453cd81a045001ad1f00d5235f4bd80d3f1da2
+++ pidgin/plugins/history.c 5ff95a8d31749632771b6df1dcffc5fc11011a13
@@ -47,10 +47,11 @@ static void historize(PurpleConversation
convtype = purple_conversation_get_type(c);
gtkconv = PIDGIN_CONVERSATION(c);
- if (gtkconv == NULL)
- return;
+ g_return_if_fail(gtkconv != NULL);
- if (convtype == PURPLE_CONV_TYPE_IM && g_list_length(gtkconv->convs) < 2)
+ /* An IM which is the first active conversation. */
+ g_return_if_fail(gtkconv->convs != NULL);
+ if (convtype == PURPLE_CONV_TYPE_IM && !gtkconv->convs->next)
{
GSList *buddies;
GSList *cur;
More information about the Commits
mailing list