strv: get rid of strv_clear()
Let's remove a function of questionnable utility. strv_clear() frees the items of a string array, but not the array itself. i.e. it half-drestructs a string array and makes it empty. This is not too useful an operation since we almost never need to just do that, we also want to free the whole thing. In fact, strv_clear() is only used in one of our .c file, and there it appears like unnecessary optimization, given that for each array with n elements it leaves the number of free()s we need to at O(n) which is not really an optimization at all (it goes from n+1 to n, that's all). Prompted by the discussions on #14605
This commit is contained in:
+2
-7
@@ -57,20 +57,15 @@ char *strv_find_startswith(char * const *l, const char *name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void strv_clear(char **l) {
|
||||
char **strv_free(char **l) {
|
||||
char **k;
|
||||
|
||||
if (!l)
|
||||
return;
|
||||
return NULL;
|
||||
|
||||
for (k = l; *k; k++)
|
||||
free(*k);
|
||||
|
||||
*l = NULL;
|
||||
}
|
||||
|
||||
char **strv_free(char **l) {
|
||||
strv_clear(l);
|
||||
return mfree(l);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user