1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

command: embedding strings to structs

Since we will make these struct const, we can also
embedding string content into them to avoid unnecessary
pointer relocations.
This commit is contained in:
Zdenek Kabelac 2024-05-01 12:45:10 +02:00
parent 6f8abdc978
commit 0b064aedb3
3 changed files with 12 additions and 16 deletions

View File

@ -48,7 +48,7 @@ static const struct val_name val_names[VAL_COUNT + 1] = {
/* create table of option names, e.g. --foo, and corresponding enum from args.h */
static struct opt_name opt_names[ARG_COUNT + 1] = {
#define arg(a, b, c, d, e, f, g) { # a, a, b, "", "--" c, d, e, f, g },
#define arg(a, b, c, d, e, f, g) { # a, b, a, "--" c, d, e, f, g },
#include "args.h"
#undef arg
};
@ -211,12 +211,9 @@ static int _val_str_to_num(char *str)
if ((new = strchr(name, '_')))
*new = '\0';
for (i = 0; i < VAL_COUNT; i++) {
if (!val_names[i].name)
break;
for (i = 0; i < VAL_COUNT; ++i)
if (!strncmp(name, val_names[i].name, strlen(val_names[i].name)))
return val_names[i].val_enum;
}
return 0;
}

View File

@ -227,11 +227,10 @@ struct command {
/* see global opt_names[] */
struct opt_name {
const char *name; /* "foo_ARG" */
uint16_t opt_enum; /* foo_ARG */
const char name[27]; /* "foo_ARG" */
const char short_opt; /* -f */
char _padding[5];
const char *long_opt; /* --foo */
uint16_t opt_enum; /* foo_ARG */
const char long_opt[28]; /* --foo */
uint16_t val_enum; /* xyz_VAL when --foo takes a val like "--foo xyz" */
uint16_t flags;
uint16_t prio;
@ -241,28 +240,28 @@ struct opt_name {
/* see global val_names[] */
struct val_name {
const char *enum_name; /* "foo_VAL" */
const char enum_name[30]; /* "foo_VAL" */
uint16_t val_enum; /* foo_VAL */
int (*fn) (struct cmd_context *cmd, struct arg_values *av); /* foo_arg() */
const char *name; /* FooVal */
const char name[32]; /* FooVal */
const char *usage;
};
/* see global lv_props[] */
struct lv_prop {
const char *enum_name; /* "is_foo_LVP" */
const char enum_name[30]; /* "is_foo_LVP" */
uint16_t lvp_enum; /* is_foo_LVP */
const char *name; /* "lv_is_foo" */
const char name[32]; /* "lv_is_foo" */
int (*fn) (struct cmd_context *cmd, struct logical_volume *lv); /* lv_is_foo() */
};
/* see global lv_types[] */
struct lv_type {
const char *enum_name; /* "foo_LVT" */
const char enum_name[30]; /* "foo_LVT" */
uint16_t lvt_enum; /* foo_LVT */
const char *name; /* "foo" */
const char name[32]; /* "foo" */
int (*fn) (struct cmd_context *cmd, struct logical_volume *lv); /* lv_is_foo() */
};

View File

@ -146,5 +146,5 @@ val(dumptype_VAL, dumptype_arg, "DumpType", "headers|metadata|metadata_all|metad
val(headings_VAL, headings_arg, "HeadingsType", "none|abbrev|full|0|1|2")
/* this should always be last */
val(VAL_COUNT, NULL, NULL, NULL)
val(VAL_COUNT, NULL, "", NULL)