Mercurial > pidgin.yaz
comparison libpurple/protocols/myspace/message.c @ 24497:f10aba5592c6
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.
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Thu, 27 Nov 2008 05:54:09 +0000 |
parents | 9479cf89a97d |
children | 0e8d91cdd63a |
comparison
equal
deleted
inserted
replaced
24496:cd70713a996d | 24497:f10aba5592c6 |
---|---|
611 msim_msg_pack_using(MsimMessage *msg, | 611 msim_msg_pack_using(MsimMessage *msg, |
612 GFunc gf, | 612 GFunc gf, |
613 const gchar *sep, | 613 const gchar *sep, |
614 const gchar *begin, const gchar *end) | 614 const gchar *begin, const gchar *end) |
615 { | 615 { |
616 int num_items; | |
616 gchar **strings; | 617 gchar **strings; |
617 gchar **strings_tmp; | 618 gchar **strings_tmp; |
618 gchar *joined; | 619 gchar *joined; |
619 gchar *final; | 620 gchar *final; |
620 int i; | 621 int i; |
621 | 622 |
622 g_return_val_if_fail(msg != NULL, NULL); | 623 g_return_val_if_fail(msg != NULL, NULL); |
623 | 624 |
625 num_items = g_list_length(msg); | |
626 | |
624 /* Add one for NULL terminator for g_strjoinv(). */ | 627 /* Add one for NULL terminator for g_strjoinv(). */ |
625 strings = (gchar **)g_new0(gchar *, g_list_length(msg) + 1); | 628 strings = (gchar **)g_new0(gchar *, num_items + 1); |
626 | 629 |
627 strings_tmp = strings; | 630 strings_tmp = strings; |
628 g_list_foreach(msg, gf, &strings_tmp); | 631 g_list_foreach(msg, gf, &strings_tmp); |
629 | 632 |
630 joined = g_strjoinv(sep, strings); | 633 joined = g_strjoinv(sep, strings); |
631 final = g_strconcat(begin, joined, end, NULL); | 634 final = g_strconcat(begin, joined, end, NULL); |
632 g_free(joined); | 635 g_free(joined); |
633 | 636 |
634 /* Clean up. */ | 637 /* Clean up. */ |
635 for (i = 0; i < g_list_length(msg); ++i) { | 638 for (i = 0; i < num_items; ++i) { |
636 g_free(strings[i]); | 639 g_free(strings[i]); |
637 } | 640 } |
638 | 641 |
639 g_free(strings); | 642 g_free(strings); |
640 | 643 |