diff 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
line wrap: on
line diff
--- a/finch/libgnt/gnttextview.c	Thu Nov 27 05:51:03 2008 +0000
+++ b/finch/libgnt/gnttextview.c	Thu Nov 27 05:54:09 2008 +0000
@@ -67,6 +67,7 @@
 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 @@
 	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 @@
 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 @@
 	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);