From 14830fda4bb2cadc3b891dad77039079935c8cc7 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 15 Apr 2009 15:04:10 -0700 Subject: [PATCH] svec: Avoid calling svec_sort() when it is not necessary. When we delete an item from a sorted array we just have to move the rest of the items down to keep it sorted; we don't have to actually re-sort the whole thing. --- lib/svec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/svec.c b/lib/svec.c index e635d499..4fc46af2 100644 --- a/lib/svec.c +++ b/lib/svec.c @@ -90,9 +90,9 @@ svec_del(struct svec *svec, const char *name) offset = svec_find(svec, name); if (offset != SIZE_MAX) { free(svec->names[offset]); - svec->names[offset] = svec->names[svec->n-1]; + memmove(&svec->names[offset], &svec->names[offset + 1], + sizeof *svec->names * (svec->n - offset - 1)); svec->n--; - svec_sort(svec); } } -- 2.30.2