mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
cleanup: use embeded list
Skip pointer and put list into selection_str_list.
This commit is contained in:
parent
6e71d3fbde
commit
83661c8f7f
@ -176,7 +176,7 @@ static struct op_def _op_log[] = {
|
|||||||
|
|
||||||
struct selection_str_list {
|
struct selection_str_list {
|
||||||
unsigned type; /* either SEL_AND or SEL_OR */
|
unsigned type; /* either SEL_AND or SEL_OR */
|
||||||
struct dm_list *list;
|
struct dm_list list;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct field_selection_value {
|
struct field_selection_value {
|
||||||
@ -1646,14 +1646,14 @@ static int _cmp_field_time(struct dm_report *rh,
|
|||||||
static int _cmp_field_string_list_strict_all(const struct str_list_sort_value *val,
|
static int _cmp_field_string_list_strict_all(const struct str_list_sort_value *val,
|
||||||
const struct selection_str_list *sel)
|
const struct selection_str_list *sel)
|
||||||
{
|
{
|
||||||
unsigned int sel_list_size = dm_list_size(sel->list);
|
unsigned int sel_list_size = dm_list_size(&sel->list);
|
||||||
struct dm_str_list *sel_item;
|
struct dm_str_list *sel_item;
|
||||||
unsigned int i = 1;
|
unsigned int i = 1;
|
||||||
|
|
||||||
if (!val->items[0].len) {
|
if (!val->items[0].len) {
|
||||||
if (sel_list_size == 1) {
|
if (sel_list_size == 1) {
|
||||||
/* match blank string list with selection defined as blank string only */
|
/* match blank string list with selection defined as blank string only */
|
||||||
sel_item = dm_list_item(dm_list_first(sel->list), struct dm_str_list);
|
sel_item = dm_list_item(dm_list_first(&sel->list), struct dm_str_list);
|
||||||
return !strcmp(sel_item->str, "");
|
return !strcmp(sel_item->str, "");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -1664,7 +1664,7 @@ static int _cmp_field_string_list_strict_all(const struct str_list_sort_value *v
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* both lists are sorted so they either match 1:1 or not */
|
/* both lists are sorted so they either match 1:1 or not */
|
||||||
dm_list_iterate_items(sel_item, sel->list) {
|
dm_list_iterate_items(sel_item, &sel->list) {
|
||||||
if ((strlen(sel_item->str) != val->items[i].len) ||
|
if ((strlen(sel_item->str) != val->items[i].len) ||
|
||||||
strncmp(sel_item->str, val->value + val->items[i].pos, val->items[i].len))
|
strncmp(sel_item->str, val->value + val->items[i].pos, val->items[i].len))
|
||||||
return 0;
|
return 0;
|
||||||
@ -1678,7 +1678,7 @@ static int _cmp_field_string_list_strict_all(const struct str_list_sort_value *v
|
|||||||
static int _cmp_field_string_list_subset_all(const struct str_list_sort_value *val,
|
static int _cmp_field_string_list_subset_all(const struct str_list_sort_value *val,
|
||||||
const struct selection_str_list *sel)
|
const struct selection_str_list *sel)
|
||||||
{
|
{
|
||||||
unsigned int sel_list_size = dm_list_size(sel->list);
|
unsigned int sel_list_size = dm_list_size(&sel->list);
|
||||||
struct dm_str_list *sel_item;
|
struct dm_str_list *sel_item;
|
||||||
unsigned int i, last_found = 1;
|
unsigned int i, last_found = 1;
|
||||||
int r = 0;
|
int r = 0;
|
||||||
@ -1686,14 +1686,14 @@ static int _cmp_field_string_list_subset_all(const struct str_list_sort_value *v
|
|||||||
if (!val->items[0].len) {
|
if (!val->items[0].len) {
|
||||||
if (sel_list_size == 1) {
|
if (sel_list_size == 1) {
|
||||||
/* match blank string list with selection defined as blank string only */
|
/* match blank string list with selection defined as blank string only */
|
||||||
sel_item = dm_list_item(dm_list_first(sel->list), struct dm_str_list);
|
sel_item = dm_list_item(dm_list_first(&sel->list), struct dm_str_list);
|
||||||
return !strcmp(sel_item->str, "");
|
return !strcmp(sel_item->str, "");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check selection is a subset of the value */
|
/* check selection is a subset of the value */
|
||||||
dm_list_iterate_items(sel_item, sel->list) {
|
dm_list_iterate_items(sel_item, &sel->list) {
|
||||||
r = 0;
|
r = 0;
|
||||||
for (i = last_found; i <= val->items[0].len; i++) {
|
for (i = last_found; i <= val->items[0].len; i++) {
|
||||||
if ((strlen(sel_item->str) == val->items[i].len) &&
|
if ((strlen(sel_item->str) == val->items[i].len) &&
|
||||||
@ -1718,14 +1718,14 @@ static int _cmp_field_string_list_any(const struct str_list_sort_value *val,
|
|||||||
|
|
||||||
/* match blank string list with selection that contains blank string */
|
/* match blank string list with selection that contains blank string */
|
||||||
if (!val->items[0].len) {
|
if (!val->items[0].len) {
|
||||||
dm_list_iterate_items(sel_item, sel->list) {
|
dm_list_iterate_items(sel_item, &sel->list) {
|
||||||
if (!strcmp(sel_item->str, ""))
|
if (!strcmp(sel_item->str, ""))
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
dm_list_iterate_items(sel_item, sel->list) {
|
dm_list_iterate_items(sel_item, &sel->list) {
|
||||||
/*
|
/*
|
||||||
* TODO: Optimize this so we don't need to compare the whole lists' content.
|
* TODO: Optimize this so we don't need to compare the whole lists' content.
|
||||||
* Make use of the fact that the lists are sorted!
|
* Make use of the fact that the lists are sorted!
|
||||||
@ -2577,12 +2577,11 @@ static const char *_tok_value_string_list(const struct dm_report_field_type *ft,
|
|||||||
int list_end = 0;
|
int list_end = 0;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
if (!(ssl = dm_pool_alloc(mem, sizeof(*ssl))) ||
|
if (!(ssl = dm_pool_alloc(mem, sizeof(*ssl)))) {
|
||||||
!(ssl->list = dm_pool_alloc(mem, sizeof(*ssl->list)))) {
|
|
||||||
log_error("_tok_value_string_list: memory allocation failed for selection list");
|
log_error("_tok_value_string_list: memory allocation failed for selection list");
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
dm_list_init(ssl->list);
|
dm_list_init(&ssl->list);
|
||||||
ssl->type = 0;
|
ssl->type = 0;
|
||||||
*begin = s;
|
*begin = s;
|
||||||
|
|
||||||
@ -2593,7 +2592,7 @@ static const char *_tok_value_string_list(const struct dm_report_field_type *ft,
|
|||||||
log_error(_str_list_item_parsing_failed, ft->id);
|
log_error(_str_list_item_parsing_failed, ft->id);
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
if (!_add_item_to_string_list(mem, begin_item, end_item, ssl->list))
|
if (!_add_item_to_string_list(mem, begin_item, end_item, &ssl->list))
|
||||||
goto_bad;
|
goto_bad;
|
||||||
ssl->type = SEL_OR | SEL_LIST_LS;
|
ssl->type = SEL_OR | SEL_LIST_LS;
|
||||||
goto out;
|
goto out;
|
||||||
@ -2650,7 +2649,7 @@ static const char *_tok_value_string_list(const struct dm_report_field_type *ft,
|
|||||||
ssl->type = end_op_flag_hit;
|
ssl->type = end_op_flag_hit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_add_item_to_string_list(mem, begin_item, end_item, ssl->list))
|
if (!_add_item_to_string_list(mem, begin_item, end_item, &ssl->list))
|
||||||
goto_bad;
|
goto_bad;
|
||||||
|
|
||||||
s = tmp;
|
s = tmp;
|
||||||
@ -2671,7 +2670,7 @@ static const char *_tok_value_string_list(const struct dm_report_field_type *ft,
|
|||||||
ssl->type |= SEL_LIST_SUBSET_LS;
|
ssl->type |= SEL_LIST_SUBSET_LS;
|
||||||
|
|
||||||
/* Sort the list. */
|
/* Sort the list. */
|
||||||
if (!(list_size = dm_list_size(ssl->list))) {
|
if (!(list_size = dm_list_size(&ssl->list))) {
|
||||||
log_error(INTERNAL_ERROR "_tok_value_string_list: list has no items");
|
log_error(INTERNAL_ERROR "_tok_value_string_list: list has no items");
|
||||||
goto bad;
|
goto bad;
|
||||||
} else if (list_size == 1)
|
} else if (list_size == 1)
|
||||||
@ -2682,18 +2681,19 @@ static const char *_tok_value_string_list(const struct dm_report_field_type *ft,
|
|||||||
}
|
}
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
dm_list_iterate_items(item, ssl->list)
|
dm_list_iterate_items(item, &ssl->list)
|
||||||
arr[i++] = item;
|
arr[i++] = item;
|
||||||
qsort(arr, list_size, sizeof(item), _str_list_item_cmp);
|
qsort(arr, list_size, sizeof(item), _str_list_item_cmp);
|
||||||
dm_list_init(ssl->list);
|
dm_list_init(&ssl->list);
|
||||||
for (i = 0; i < list_size; i++)
|
for (i = 0; i < list_size; i++)
|
||||||
dm_list_add(ssl->list, &arr[i]->list);
|
dm_list_add(&ssl->list, &arr[i]->list);
|
||||||
|
|
||||||
dm_free(arr);
|
dm_free(arr);
|
||||||
out:
|
out:
|
||||||
*end = s;
|
*end = s;
|
||||||
if (sel_str_list)
|
if (sel_str_list)
|
||||||
*sel_str_list = ssl;
|
*sel_str_list = ssl;
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
bad:
|
bad:
|
||||||
*end = s;
|
*end = s;
|
||||||
|
Loading…
Reference in New Issue
Block a user