Make smartlist_add_all more efficient.

svn:r5086
This commit is contained in:
Nick Mathewson 2005-09-18 02:17:02 +00:00
parent d69089fc64
commit 312af36126

View File

@ -109,7 +109,16 @@ smartlist_add(smartlist_t *sl, void *element) {
void void
smartlist_add_all(smartlist_t *sl, const smartlist_t *s2) 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 /** Remove all elements E from sl such that E==element. Preserve