mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-09 22:03:12 +00:00
lib: add vector_compact(), use after str splits
* Add function to move all data to the start of a vector by shifting over contiguous empty slots * Use this function to remove empty slots leftover after frrstr_filter_vec Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
This commit is contained in:
parent
5d806ec6e0
commit
f428cb8a3a
@ -290,10 +290,12 @@ vector cmd_make_strvec(const char *string)
|
|||||||
for (unsigned int i = 0; i < vector_active(result); i++) {
|
for (unsigned int i = 0; i < vector_active(result); i++) {
|
||||||
if (strlen(vector_slot(result, i)) == 0) {
|
if (strlen(vector_slot(result, i)) == 0) {
|
||||||
XFREE(MTYPE_TMP, vector_slot(result, i));
|
XFREE(MTYPE_TMP, vector_slot(result, i));
|
||||||
vector_remove(result, i);
|
vector_unset(result, i);
|
||||||
--i;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector_compact(result);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
lib/vector.c
10
lib/vector.c
@ -164,6 +164,16 @@ void vector_remove(vector v, unsigned int ix)
|
|||||||
v->index[v->active] = NULL;
|
v->index[v->active] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vector_compact(vector v)
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0; i < vector_active(v); ++i) {
|
||||||
|
if (vector_slot(v, i) == NULL) {
|
||||||
|
vector_remove(v, i);
|
||||||
|
--i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void vector_unset_value(vector v, void *val)
|
void vector_unset_value(vector v, void *val)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
@ -53,6 +53,7 @@ extern int vector_set_index(vector v, unsigned int i, void *val);
|
|||||||
extern void vector_unset(vector v, unsigned int i);
|
extern void vector_unset(vector v, unsigned int i);
|
||||||
extern void vector_unset_value(vector v, void *val);
|
extern void vector_unset_value(vector v, void *val);
|
||||||
extern void vector_remove(vector v, unsigned int ix);
|
extern void vector_remove(vector v, unsigned int ix);
|
||||||
|
extern void vector_compact(vector v);
|
||||||
|
|
||||||
extern unsigned int vector_count(vector v);
|
extern unsigned int vector_count(vector v);
|
||||||
extern void vector_free(vector v);
|
extern void vector_free(vector v);
|
||||||
|
@ -188,6 +188,7 @@ int vty_out(struct vty *vty, const char *format, ...)
|
|||||||
vector lines = frrstr_split_vec(buf, "\n");
|
vector lines = frrstr_split_vec(buf, "\n");
|
||||||
|
|
||||||
frrstr_filter_vec(lines, &vty->include);
|
frrstr_filter_vec(lines, &vty->include);
|
||||||
|
vector_compact(lines);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Consider the string "foo\n". If the regex is an empty string
|
* Consider the string "foo\n". If the regex is an empty string
|
||||||
|
Loading…
Reference in New Issue
Block a user