Explorar o código

Make smartlist_add_all more efficient.

svn:r5086
Nick Mathewson %!s(int64=20) %!d(string=hai) anos
pai
achega
312af36126
Modificáronse 1 ficheiros con 10 adicións e 1 borrados
  1. 10 1
      src/common/container.c

+ 10 - 1
src/common/container.c

@@ -109,7 +109,16 @@ smartlist_add(smartlist_t *sl, void *element) {
 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