1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-26 17:25:10 +03:00

export: reduce emit_to_buffer calls

As the 'emit_to_buffer' uses relatively complex
vsnprintf() call inside, try to reduce number
of unnecessary calls and try replace some more
complex string build with a single call instead.
This commit is contained in:
Zdenek Kabelac 2024-10-20 22:14:39 +02:00
parent 7156b4930d
commit 4929c55bc5
2 changed files with 17 additions and 42 deletions

View File

@ -367,11 +367,11 @@ static int _print_flag_config(struct formatter *f, uint64_t status, enum pv_vg_l
if (!print_flags(buffer, sizeof(buffer), type, STATUS_FLAG, status)) if (!print_flags(buffer, sizeof(buffer), type, STATUS_FLAG, status))
return_0; return_0;
outf(f, "status = %s", buffer); outf(f, "status = [%s]", buffer);
if (!print_flags(buffer, sizeof(buffer), type, COMPATIBLE_FLAG, status)) if (!print_flags(buffer, sizeof(buffer), type, COMPATIBLE_FLAG, status))
return_0; return_0;
outf(f, "flags = %s", buffer); outf(f, "flags = [%s]", buffer);
return 1; return 1;
} }
@ -394,22 +394,14 @@ static char *_alloc_printed_str_list(struct dm_list *list)
return NULL; return NULL;
} }
if (!emit_to_buffer(&buf, &size, "["))
goto_bad;
dm_list_iterate_items(sl, list) { dm_list_iterate_items(sl, list) {
if (!first) { if (!emit_to_buffer(&buf, &size, "%s\"%s\"",
if (!emit_to_buffer(&buf, &size, ", ")) (!first) ? ", " : "",
goto_bad; sl->str))
} else
first = 0;
if (!emit_to_buffer(&buf, &size, "\"%s\"", sl->str))
goto_bad; goto_bad;
}
if (!emit_to_buffer(&buf, &size, "]")) first = 0;
goto_bad; }
return buffer; return buffer;
@ -426,7 +418,7 @@ static int _out_list(struct formatter *f, struct dm_list *list,
if (!dm_list_empty(list)) { if (!dm_list_empty(list)) {
if (!(buffer = _alloc_printed_str_list(list))) if (!(buffer = _alloc_printed_str_list(list)))
return_0; return_0;
if (!out_text(f, "%s = %s", list_name, buffer)) { if (!out_text(f, "%s = [%s]", list_name, buffer)) {
free(buffer); free(buffer);
return_0; return_0;
} }
@ -848,24 +840,17 @@ static int _alloc_printed_indirect_descendants(struct dm_list *indirect_glvs, ch
} }
buf = *buffer; buf = *buffer;
if (!emit_to_buffer(&buf, &buf_size, "["))
goto_bad;
dm_list_iterate_items(user_glvl, indirect_glvs) { dm_list_iterate_items(user_glvl, indirect_glvs) {
if (user_glvl->glv->is_historical) if (user_glvl->glv->is_historical)
continue; continue;
if (!first) {
if (!emit_to_buffer(&buf, &buf_size, ", "))
goto_bad;
} else
first = 0;
if (!emit_to_buffer(&buf, &buf_size, "\"%s\"", user_glvl->glv->live->name)) if (!emit_to_buffer(&buf, &buf_size, "%s\"%s\"",
(!first) ? ", " : "",
user_glvl->glv->live->name))
goto_bad; goto_bad;
}
if (!emit_to_buffer(&buf, &buf_size, "]")) first = 0;
goto_bad; }
return 1; return 1;
bad: bad:
@ -904,7 +889,7 @@ static int _print_historical_lv_with_descendants(struct formatter *f, struct his
} }
if (descendants_buffer) if (descendants_buffer)
outf(f, "descendants = %s", descendants_buffer); outf(f, "descendants = [%s]", descendants_buffer);
_dec_indent(f); _dec_indent(f);
outf(f, "}"); outf(f, "}");

View File

@ -144,9 +144,6 @@ int print_flags(char *buffer, size_t size, enum pv_vg_lv_e type, int mask, uint6
if (!(flags = _get_flags(type))) if (!(flags = _get_flags(type)))
return_0; return_0;
if (!emit_to_buffer(&buffer, &size, "["))
return_0;
for (f = 0; flags[f].mask; f++) { for (f = 0; flags[f].mask; f++) {
if (status & flags[f].mask) { if (status & flags[f].mask) {
status &= ~flags[f].mask; status &= ~flags[f].mask;
@ -158,21 +155,14 @@ int print_flags(char *buffer, size_t size, enum pv_vg_lv_e type, int mask, uint6
if (!flags[f].description) if (!flags[f].description)
continue; continue;
if (!first) { if (!emit_to_buffer(&buffer, &size, "%s\"%s\"",
if (!emit_to_buffer(&buffer, &size, ", ")) (!first) ? ", " : "",
return_0;
} else
first = 0;
if (!emit_to_buffer(&buffer, &size, "\"%s\"",
flags[f].description)) flags[f].description))
return_0; return_0;
first = 0;
} }
} }
if (!emit_to_buffer(&buffer, &size, "]"))
return_0;
if (status) if (status)
log_warn(INTERNAL_ERROR "Metadata inconsistency: " log_warn(INTERNAL_ERROR "Metadata inconsistency: "
"Not all flags successfully exported."); "Not all flags successfully exported.");