diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-09-18 02:17:02 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-09-18 02:17:02 +0000 |
commit | 312af361269a1b82e3e1b2df3a961eba8748f0ad (patch) | |
tree | bf295e5eb1b4c9ee3a6e94a24496ea4e11c19399 /src/common/container.c | |
parent | d69089fc642b16e242efffed036d19ffbca6f633 (diff) | |
download | tor-312af361269a1b82e3e1b2df3a961eba8748f0ad.tar tor-312af361269a1b82e3e1b2df3a961eba8748f0ad.tar.gz |
Make smartlist_add_all more efficient.
svn:r5086
Diffstat (limited to 'src/common/container.c')
-rw-r--r-- | src/common/container.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/common/container.c b/src/common/container.c index 42651b83d..4c8703ca3 100644 --- a/src/common/container.c +++ b/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 |