mirror of
https://github.com/systemd/systemd.git
synced 2025-03-28 02:50:16 +03:00
shared/format-table: use goto to make code flow clear
gcc 9.3.0 "cc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0" with --optimization=1 was not able to figure out that all cases are covered because r is either set in the switch or type < _TABLE_DATA_TYPE_MAX. But for a human reader this might also not be obvious: the cases are not in exactly the same order as enum definitions, and it's a long list. By using the goto, there should be no doubt, and we avoid checking the condition a second time.
This commit is contained in:
parent
4a3ad75efa
commit
46cbdcd9fe
@ -966,43 +966,43 @@ int table_add_many_internal(Table *t, TableDataType first_type, ...) {
|
||||
size_t w = va_arg(ap, size_t);
|
||||
|
||||
r = table_set_minimum_width(t, last_cell, w);
|
||||
break;
|
||||
goto check;
|
||||
}
|
||||
|
||||
case TABLE_SET_MAXIMUM_WIDTH: {
|
||||
size_t w = va_arg(ap, size_t);
|
||||
r = table_set_maximum_width(t, last_cell, w);
|
||||
break;
|
||||
goto check;
|
||||
}
|
||||
|
||||
case TABLE_SET_WEIGHT: {
|
||||
unsigned w = va_arg(ap, unsigned);
|
||||
r = table_set_weight(t, last_cell, w);
|
||||
break;
|
||||
goto check;
|
||||
}
|
||||
|
||||
case TABLE_SET_ALIGN_PERCENT: {
|
||||
unsigned p = va_arg(ap, unsigned);
|
||||
r = table_set_align_percent(t, last_cell, p);
|
||||
break;
|
||||
goto check;
|
||||
}
|
||||
|
||||
case TABLE_SET_ELLIPSIZE_PERCENT: {
|
||||
unsigned p = va_arg(ap, unsigned);
|
||||
r = table_set_ellipsize_percent(t, last_cell, p);
|
||||
break;
|
||||
goto check;
|
||||
}
|
||||
|
||||
case TABLE_SET_COLOR: {
|
||||
const char *c = va_arg(ap, const char*);
|
||||
r = table_set_color(t, last_cell, c);
|
||||
break;
|
||||
goto check;
|
||||
}
|
||||
|
||||
case TABLE_SET_RGAP_COLOR: {
|
||||
const char *c = va_arg(ap, const char*);
|
||||
r = table_set_rgap_color(t, last_cell, c);
|
||||
break;
|
||||
goto check;
|
||||
}
|
||||
|
||||
case TABLE_SET_BOTH_COLORS: {
|
||||
@ -1015,19 +1015,19 @@ int table_add_many_internal(Table *t, TableDataType first_type, ...) {
|
||||
}
|
||||
|
||||
r = table_set_rgap_color(t, last_cell, c);
|
||||
break;
|
||||
goto check;
|
||||
}
|
||||
|
||||
case TABLE_SET_URL: {
|
||||
const char *u = va_arg(ap, const char*);
|
||||
r = table_set_url(t, last_cell, u);
|
||||
break;
|
||||
goto check;
|
||||
}
|
||||
|
||||
case TABLE_SET_UPPERCASE: {
|
||||
int u = va_arg(ap, int);
|
||||
r = table_set_uppercase(t, last_cell, u);
|
||||
break;
|
||||
goto check;
|
||||
}
|
||||
|
||||
case _TABLE_DATA_TYPE_MAX:
|
||||
@ -1039,9 +1039,8 @@ int table_add_many_internal(Table *t, TableDataType first_type, ...) {
|
||||
assert_not_reached("Uh? Unexpected data type.");
|
||||
}
|
||||
|
||||
if (type < _TABLE_DATA_TYPE_MAX)
|
||||
r = table_add_cell(t, &last_cell, type, data);
|
||||
|
||||
r = table_add_cell(t, &last_cell, type, data);
|
||||
check:
|
||||
if (r < 0) {
|
||||
va_end(ap);
|
||||
return r;
|
||||
|
Loading…
x
Reference in New Issue
Block a user