From: Ben Pfaff Date: Wed, 15 Apr 2009 22:04:10 +0000 (-0700) Subject: svec: Avoid calling svec_sort() when it is not necessary. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=14830fda4bb2cadc3b891dad77039079935c8cc7;p=openvswitch 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. --- 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); } }