changeset 392:6329c9601704

Speed up hbuf_add_line() When loading a history file, *p_hbuf was a pointer to the head of the list of lines, so a lot of CPU time was lost in g_list_last().
author Mikael Berthe <mikael@lilotux.net>
date Thu, 04 Aug 2005 22:55:10 +0100
parents 868a350fefca
children f8f3c7493457
files mcabber/src/hbuf.c
diffstat 1 files changed, 7 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/hbuf.c	Thu Aug 04 09:00:54 2005 +0100
+++ b/mcabber/src/hbuf.c	Thu Aug 04 22:55:10 2005 +0100
@@ -67,11 +67,14 @@
     hbuf_block_elt->ptr_end_alloc = hbuf_block_elt->ptr + HBB_BLOCKSIZE;
     *p_hbuf = g_list_append(*p_hbuf, hbuf_block_elt);
   } else {
-    hbuf_block *hbuf_b_prev = g_list_last(hbuf)->data;
+    // Set p_hbuf to the end of the list, to speed up history loading
+    // (or CPU time will be used by g_list_last() for each line)
+    hbuf = *p_hbuf = g_list_last(*p_hbuf);
+    hbuf_block *hbuf_b_prev = hbuf->data;
     hbuf_block_elt->ptr    = hbuf_b_prev->ptr_end;
     hbuf_block_elt->flags  = HBB_FLAG_PERSISTENT;
     hbuf_block_elt->ptr_end_alloc = hbuf_b_prev->ptr_end_alloc;
-    *p_hbuf = g_list_append(*p_hbuf, hbuf_block_elt);
+    g_list_append(*p_hbuf, hbuf_block_elt);
   }
 
   if (strlen(text) >= HBB_BLOCKSIZE) {
@@ -109,7 +112,7 @@
       hbuf_block_elt->ptr_end  = end;
       hbuf_block_elt->flags    = HBB_FLAG_PERSISTENT;
       hbuf_block_elt->ptr_end_alloc = hbuf_b_prev->ptr_end_alloc;
-      *p_hbuf = g_list_append(*p_hbuf, hbuf_block_elt);
+      g_list_append(*p_hbuf, hbuf_block_elt);
       line = hbuf_block_elt->ptr;
     } else {
       // We need to break where we can find a space char
@@ -127,7 +130,7 @@
       hbuf_block_elt->ptr_end  = end;
       hbuf_block_elt->flags    = 0;
       hbuf_block_elt->ptr_end_alloc = hbuf_b_prev->ptr_end_alloc;
-      *p_hbuf = g_list_append(*p_hbuf, hbuf_block_elt);
+      g_list_append(*p_hbuf, hbuf_block_elt);
       line = hbuf_block_elt->ptr;
     }
     cr = strchr(line, '\n');