Mercurial > pidgin.yaz
comparison finch/libgnt/gnttextview.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 | c38d72677c8a |
children | e2e57d3c0578 |
comparison
equal
deleted
inserted
replaced
24496:cd70713a996d | 24497:f10aba5592c6 |
---|---|
65 | 65 |
66 static void | 66 static void |
67 gnt_text_view_draw(GntWidget *widget) | 67 gnt_text_view_draw(GntWidget *widget) |
68 { | 68 { |
69 GntTextView *view = GNT_TEXT_VIEW(widget); | 69 GntTextView *view = GNT_TEXT_VIEW(widget); |
70 int n; | |
70 int i = 0; | 71 int i = 0; |
71 GList *lines; | 72 GList *lines; |
72 int rows, scrcol; | 73 int rows, scrcol; |
73 int comp = 0; /* Used for top-aligned text */ | 74 int comp = 0; /* Used for top-aligned text */ |
74 gboolean has_scroll = !(view->flags & GNT_TEXT_VIEW_NO_SCROLL); | 75 gboolean has_scroll = !(view->flags & GNT_TEXT_VIEW_NO_SCROLL); |
75 | 76 |
76 wbkgd(widget->window, gnt_color_pair(GNT_COLOR_NORMAL)); | 77 wbkgd(widget->window, gnt_color_pair(GNT_COLOR_NORMAL)); |
77 werase(widget->window); | 78 werase(widget->window); |
78 | 79 |
80 n = g_list_length(view->list); | |
79 if ((view->flags & GNT_TEXT_VIEW_TOP_ALIGN) && | 81 if ((view->flags & GNT_TEXT_VIEW_TOP_ALIGN) && |
80 g_list_length(view->list) < widget->priv.height) { | 82 n < widget->priv.height) { |
81 GList *now = view->list; | 83 GList *now = view->list; |
82 comp = widget->priv.height - g_list_length(view->list); | 84 comp = widget->priv.height - n; |
83 view->list = g_list_nth_prev(view->list, comp); | 85 view->list = g_list_nth_prev(view->list, comp); |
84 if (!view->list) { | 86 if (!view->list) { |
85 view->list = g_list_first(now); | 87 view->list = g_list_first(now); |
86 comp = widget->priv.height - g_list_length(view->list); | 88 comp = widget->priv.height - g_list_length(view->list); |
87 } else { | 89 } else { |
234 } | 236 } |
235 | 237 |
236 static char * | 238 static char * |
237 gnt_text_view_get_p(GntTextView *view, int x, int y) | 239 gnt_text_view_get_p(GntTextView *view, int x, int y) |
238 { | 240 { |
241 int n; | |
239 int i = 0; | 242 int i = 0; |
240 GntWidget *wid = GNT_WIDGET(view); | 243 GntWidget *wid = GNT_WIDGET(view); |
241 GntTextLine *line; | 244 GntTextLine *line; |
242 GList *lines; | 245 GList *lines; |
243 GList *segs; | 246 GList *segs; |
244 GntTextSegment *seg; | 247 GntTextSegment *seg; |
245 gchar *pos; | 248 gchar *pos; |
246 | 249 |
250 n = g_list_length(view->list); | |
247 y = wid->priv.height - y; | 251 y = wid->priv.height - y; |
248 if (g_list_length(view->list) < y) { | 252 if (n < y) { |
249 x = 0; | 253 x = 0; |
250 y = g_list_length(view->list) - 1; | 254 y = n - 1; |
251 } | 255 } |
252 | 256 |
253 lines = g_list_nth(view->list, y - 1); | 257 lines = g_list_nth(view->list, y - 1); |
254 if (!lines) | 258 if (!lines) |
255 return NULL; | 259 return NULL; |