mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +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:
parent
6f8abdc978
commit
0b064aedb3
@ -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 */
|
/* create table of option names, e.g. --foo, and corresponding enum from args.h */
|
||||||
|
|
||||||
static struct opt_name opt_names[ARG_COUNT + 1] = {
|
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"
|
#include "args.h"
|
||||||
#undef arg
|
#undef arg
|
||||||
};
|
};
|
||||||
@ -211,12 +211,9 @@ static int _val_str_to_num(char *str)
|
|||||||
if ((new = strchr(name, '_')))
|
if ((new = strchr(name, '_')))
|
||||||
*new = '\0';
|
*new = '\0';
|
||||||
|
|
||||||
for (i = 0; i < VAL_COUNT; i++) {
|
for (i = 0; i < VAL_COUNT; ++i)
|
||||||
if (!val_names[i].name)
|
|
||||||
break;
|
|
||||||
if (!strncmp(name, val_names[i].name, strlen(val_names[i].name)))
|
if (!strncmp(name, val_names[i].name, strlen(val_names[i].name)))
|
||||||
return val_names[i].val_enum;
|
return val_names[i].val_enum;
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -227,11 +227,10 @@ struct command {
|
|||||||
/* see global opt_names[] */
|
/* see global opt_names[] */
|
||||||
|
|
||||||
struct opt_name {
|
struct opt_name {
|
||||||
const char *name; /* "foo_ARG" */
|
const char name[27]; /* "foo_ARG" */
|
||||||
uint16_t opt_enum; /* foo_ARG */
|
|
||||||
const char short_opt; /* -f */
|
const char short_opt; /* -f */
|
||||||
char _padding[5];
|
uint16_t opt_enum; /* foo_ARG */
|
||||||
const char *long_opt; /* --foo */
|
const char long_opt[28]; /* --foo */
|
||||||
uint16_t val_enum; /* xyz_VAL when --foo takes a val like "--foo xyz" */
|
uint16_t val_enum; /* xyz_VAL when --foo takes a val like "--foo xyz" */
|
||||||
uint16_t flags;
|
uint16_t flags;
|
||||||
uint16_t prio;
|
uint16_t prio;
|
||||||
@ -241,28 +240,28 @@ struct opt_name {
|
|||||||
/* see global val_names[] */
|
/* see global val_names[] */
|
||||||
|
|
||||||
struct val_name {
|
struct val_name {
|
||||||
const char *enum_name; /* "foo_VAL" */
|
const char enum_name[30]; /* "foo_VAL" */
|
||||||
uint16_t val_enum; /* foo_VAL */
|
uint16_t val_enum; /* foo_VAL */
|
||||||
int (*fn) (struct cmd_context *cmd, struct arg_values *av); /* foo_arg() */
|
int (*fn) (struct cmd_context *cmd, struct arg_values *av); /* foo_arg() */
|
||||||
const char *name; /* FooVal */
|
const char name[32]; /* FooVal */
|
||||||
const char *usage;
|
const char *usage;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* see global lv_props[] */
|
/* see global lv_props[] */
|
||||||
|
|
||||||
struct lv_prop {
|
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 */
|
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() */
|
int (*fn) (struct cmd_context *cmd, struct logical_volume *lv); /* lv_is_foo() */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* see global lv_types[] */
|
/* see global lv_types[] */
|
||||||
|
|
||||||
struct lv_type {
|
struct lv_type {
|
||||||
const char *enum_name; /* "foo_LVT" */
|
const char enum_name[30]; /* "foo_LVT" */
|
||||||
uint16_t lvt_enum; /* 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() */
|
int (*fn) (struct cmd_context *cmd, struct logical_volume *lv); /* lv_is_foo() */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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")
|
val(headings_VAL, headings_arg, "HeadingsType", "none|abbrev|full|0|1|2")
|
||||||
|
|
||||||
/* this should always be last */
|
/* this should always be last */
|
||||||
val(VAL_COUNT, NULL, NULL, NULL)
|
val(VAL_COUNT, NULL, "", NULL)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user