qulogic/libgnt

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.
  • +8 -4
    gnttextview.c
  • +5 -3
    gntwm.c
  • --- a/gnttextview.c Fri Nov 14 03:04:38 2008 +0000
    +++ b/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);
    --- a/gntwm.c Fri Nov 14 03:04:38 2008 +0000
    +++ b/gntwm.c Thu Nov 27 05:54:09 2008 +0000
    @@ -201,7 +201,7 @@
    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 @@
    GntWidget *tree, *win;
    GList *iter;
    GntWM *wm = GNT_WM(bindable);
    + int n;
    if (wm->_list.window || wm->menu)
    return TRUE;
    @@ -950,8 +951,9 @@
    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;