Changeset 95062 in webkit


Ignore:
Timestamp:
Sep 13, 2011 6:03:47 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

GTK DumpRenderTree uses inefficient idioms to iterate over G[S]Lists
https://bugs.webkit.org/show_bug.cgi?id=68024

Patch by Leandro Pereira <leandro@profusion.mobi> on 2011-09-13
Reviewed by Gustavo Noronha Silva.

Using g_list_count() and g_list_nth_data() together on a loop is
inneficient since they're both O(n). Iterate over lists in a saner
way.

  • DumpRenderTree/gtk/DumpRenderTree.cpp:

(dumpHistoryItem): Reduce the scope for the 'kids' variable, and
iterate on it using g_list_next(). Free the list after done with it.
(dumpBackForwardListForWebView): Instead of appending (which is
expensive in GLists) history items and then iterating from the tail
of the itemsToPrint list, prepend items and walk forwards as usual.
(dumpBackForwardListForAllWebViews): Walk the list in a saner way,
remove the (unneeded) viewList variable.

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r95061 r95062  
     12011-09-13  Leandro Pereira  <leandro@profusion.mobi>
     2
     3        GTK DumpRenderTree uses inefficient idioms to iterate over G[S]Lists
     4        https://bugs.webkit.org/show_bug.cgi?id=68024
     5
     6        Reviewed by Gustavo Noronha Silva.
     7       
     8        Using g_list_count() and g_list_nth_data() together on a loop is
     9        inneficient since they're both O(n). Iterate over lists in a saner
     10        way.
     11
     12        * DumpRenderTree/gtk/DumpRenderTree.cpp:
     13        (dumpHistoryItem): Reduce the scope for the 'kids' variable, and
     14        iterate on it using g_list_next(). Free the list after done with it.
     15        (dumpBackForwardListForWebView): Instead of appending (which is
     16        expensive in GLists) history items and then iterating from the tail
     17        of the itemsToPrint list, prepend items and walk forwards as usual.
     18        (dumpBackForwardListForAllWebViews): Walk the list in a saner way,
     19        remove the (unneeded) viewList variable.
     20
    1212011-09-13  Ryosuke Niwa  <rniwa@webkit.org>
    222
  • trunk/Tools/DumpRenderTree/gtk/DumpRenderTree.cpp

    r94105 r95062  
    331331        printf("  **nav target**");
    332332    putchar('\n');
    333     GList* kids = webkit_web_history_item_get_children(item);
    334     if (kids) {
     333
     334    if (GList* kids = webkit_web_history_item_get_children(item)) {
    335335        // must sort to eliminate arbitrary result ordering which defeats reproducible testing
    336         kids = g_list_sort(kids, (GCompareFunc) compareHistoryItems);
    337         for (unsigned i = 0; i < g_list_length(kids); i++)
    338             dumpHistoryItem(WEBKIT_WEB_HISTORY_ITEM(g_list_nth_data(kids, i)), indent+4, FALSE);
     336        for (GList* kid = g_list_sort(kids, (GCompareFunc) compareHistoryItems); kid; kid = g_list_next(kid)) {
     337            WebKitWebHistoryItem* item = WEBKIT_WEB_HISTORY_ITEM(kid->data);
     338            dumpHistoryItem(item, indent + 4, FALSE);
     339            g_object_unref(item);
     340        }
     341        g_list_free(kids);
    339342    }
    340343    g_object_unref(item);
     
    355358        ASSERT(item != prevTestBFItem);
    356359        g_object_ref(item);
    357         itemsToPrint = g_list_append(itemsToPrint, item);
     360        itemsToPrint = g_list_prepend(itemsToPrint, item);
    358361    }
    359362
    360363    WebKitWebHistoryItem* currentItem = webkit_web_back_forward_list_get_current_item(bfList);
    361 
    362364    g_object_ref(currentItem);
    363     itemsToPrint = g_list_append(itemsToPrint, currentItem);
    364 
    365     gint currentItemIndex = g_list_length(itemsToPrint) - 1;
     365    itemsToPrint = g_list_prepend(itemsToPrint, currentItem);
     366
    366367    gint backListCount = webkit_web_back_forward_list_get_back_length(bfList);
    367368    for (int i = -1; i >= -(backListCount); i--) {
     
    370371            break;
    371372        g_object_ref(item);
    372         itemsToPrint = g_list_append(itemsToPrint, item);
    373     }
    374 
    375     for (int i = g_list_length(itemsToPrint) - 1; i >= 0; i--) {
    376         WebKitWebHistoryItem* item = WEBKIT_WEB_HISTORY_ITEM(g_list_nth_data(itemsToPrint, i));
    377         dumpHistoryItem(item, historyItemIndent, i == currentItemIndex);
     373        itemsToPrint = g_list_prepend(itemsToPrint, item);
     374    }
     375
     376    for (GList* itemToPrint = itemsToPrint; itemToPrint; itemToPrint = g_list_next(itemToPrint)) {
     377        WebKitWebHistoryItem* item = WEBKIT_WEB_HISTORY_ITEM(itemToPrint->data);
     378        dumpHistoryItem(item, historyItemIndent, item == currentItem);
    378379        g_object_unref(item);
    379380    }
     381
    380382    g_list_free(itemsToPrint);
    381383    printf("===============================================\n");
     
    388390
    389391    // The view list is prepended. Reverse the list so we get the order right.
    390     GSList* viewList = g_slist_reverse(webViewList);
    391     for (unsigned i = 0; i < g_slist_length(viewList); ++i)
    392         dumpBackForwardListForWebView(WEBKIT_WEB_VIEW(g_slist_nth_data(viewList, i)));
     392    for (GSList* currentView = g_slist_reverse(webViewList); currentView; currentView = g_slist_next(currentView))
     393        dumpBackForwardListForWebView(WEBKIT_WEB_VIEW(currentView->data));
    393394}
    394395
Note: See TracChangeset for help on using the changeset viewer.