Code

wreadln: call g_list_length() only once
authorMax Kellermann <max.kellermann@gmail.com>
Tue, 21 Mar 2017 21:28:14 +0000 (22:28 +0100)
committerMax Kellermann <max.kellermann@gmail.com>
Tue, 21 Mar 2017 21:28:14 +0000 (22:28 +0100)
src/wreadln.c

index f45e474e1e2107f7986f8c66cb6819ab32578ab7..4dde082aa2948e78f9ef4f38619188c2f940cfe8 100644 (file)
@@ -592,13 +592,15 @@ _wreadln(WINDOW *w,
                        *history = g_list_delete_link(*history, hcurrent);
                }
 
-               while (g_list_length(*history) > wrln_max_history_length) {
+               unsigned history_length = g_list_length(*history);
+               while (history_length > wrln_max_history_length) {
                        GList *first = g_list_first(*history);
 
                        /* remove the oldest history entry  */
                        g_free(first->data);
                        first->data = NULL;
                        *history = g_list_delete_link(*history, first);
+                       --history_length;
                }
        }