[libgepub/wip/cosimoc/api-rework: 11/13] doc: don't call g_list_append()



commit 36ec099e826f732ed9de046ab0f2328b2c2634a1
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sat Jun 18 13:20:39 2016 -0700

    doc: don't call g_list_append()
    
    It's more efficient to always prepend to the list and then reverse it at
    the end, since g_list_append() will walk the list at every call.

 libgepub/gepub-doc.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
---
diff --git a/libgepub/gepub-doc.c b/libgepub/gepub-doc.c
index 5e2d2cc..f8aaec6 100644
--- a/libgepub/gepub-doc.c
+++ b/libgepub/gepub-doc.c
@@ -260,6 +260,7 @@ gepub_doc_fill_spine (GepubDoc *doc)
     gchar *id;
     const char *data;
     gsize size;
+    GList *spine = NULL;
 
     data = g_bytes_get_data (doc->content, &size);
     xdoc = xmlRecoverMemory (data, size);
@@ -275,10 +276,11 @@ gepub_doc_fill_spine (GepubDoc *doc)
 
         id = xmlGetProp (item, "idref");
 
-        doc->spine = g_list_append (doc->spine, id);
+        spine = g_list_prepend (spine, id);
         item = item->next;
     }
 
+    doc->spine = g_list_reverse (spine);
     xmlFreeDoc (xdoc);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]