[or-cvs] Make smartlist_add_all more efficient.

Nick Mathewson nickm at seul.org
Sun Sep 18 02:17:04 UTC 2005


Update of /home/or/cvsroot/tor/src/common
In directory moria:/tmp/cvs-serv6651/src/common

Modified Files:
	container.c 
Log Message:
Make smartlist_add_all more efficient.

Index: container.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/container.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- container.c	13 Sep 2005 15:30:22 -0000	1.38
+++ container.c	18 Sep 2005 02:17:02 -0000	1.39
@@ -109,7 +109,16 @@
 void
 smartlist_add_all(smartlist_t *sl, const smartlist_t *s2)
 {
-  SMARTLIST_FOREACH(s2, void *, element, smartlist_add(sl, element));
+  int n2 = sl->num_used + s2->num_used;
+  if (n2 > sl->capacity) {
+    int higher = sl->capacity * 2;
+    while (n2 > higher)
+      higher *= 2;
+    sl->capacity = higher;
+    sl->list = tor_realloc(sl->list, sizeof(void*)*sl->capacity);
+  }
+  memcpy(sl->list + sl->num_used, s2->list, s2->num_used*sizeof(void*));
+  sl->num_used += s2->num_used;
 }
 
 /** Remove all elements E from sl such that E==element.  Preserve



More information about the tor-commits mailing list