summaryrefslogtreecommitdiff
path: root/src/common/container.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-11-23 14:07:53 -0500
committerNick Mathewson <nickm@torproject.org>2016-11-30 14:42:52 -0500
commit21c47c44109a9de373f40c454e653953ba21312e (patch)
tree59c0d7000483b9f1e71f170cd57a2ede38c99b5b /src/common/container.c
parentbf64564e37c5fc01111bc476d1b93890b15a18bf (diff)
downloadtor-21c47c44109a9de373f40c454e653953ba21312e.tar.gz
tor-21c47c44109a9de373f40c454e653953ba21312e.zip
Add a smartlist_remove_keeporder() function, with tests.
Diffstat (limited to 'src/common/container.c')
-rw-r--r--src/common/container.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/common/container.c b/src/common/container.c
index ec59dccf62..1448ab403c 100644
--- a/src/common/container.c
+++ b/src/common/container.c
@@ -132,6 +132,24 @@ smartlist_remove(smartlist_t *sl, const void *element)
}
}
+/** As <b>smartlist_remove</b>, but do not change the order of
+ * any elements not removed */
+void
+smartlist_remove_keeporder(smartlist_t *sl, const void *element)
+{
+ int i, j, num_used_orig = sl->num_used;
+ if (element == NULL)
+ return;
+
+ for (i=j=0; j < num_used_orig; ++j) {
+ if (sl->list[j] == element) {
+ --sl->num_used;
+ } else {
+ sl->list[i++] = sl->list[j];
+ }
+ }
+}
+
/** If <b>sl</b> is nonempty, remove and return the final element. Otherwise,
* return NULL. */
void *