mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 14:23:30 +01:00
Make smartlist_add_all more efficient.
svn:r5086
This commit is contained in:
parent
d69089fc64
commit
312af36126
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user