mirror of https://github.com/mpv-player/mpv
m_config: remove extra default_data field
Just wastes memory (a few KB, because there are so many options).
This commit is contained in:
parent
3f061dd629
commit
816ad03519
|
@ -220,12 +220,12 @@ static void alloc_group(struct m_config_data *data, int group_index,
|
|||
if (co->opt->offset < 0 || co->opt->type->size == 0)
|
||||
continue;
|
||||
|
||||
const void *defptr = co->default_data;
|
||||
void *dst = gdata->udata + co->opt->offset;
|
||||
const void *defptr = co->opt->defval ? co->opt->defval : dst;
|
||||
if (copy_src)
|
||||
defptr = copy_src + co->opt->offset;
|
||||
|
||||
if (defptr)
|
||||
init_opt_inplace(co->opt, gdata->udata + co->opt->offset, defptr);
|
||||
init_opt_inplace(co->opt, dst, defptr);
|
||||
}
|
||||
|
||||
// If there's a parent, update its pointer to the new struct.
|
||||
|
@ -529,8 +529,6 @@ static void add_sub_group(struct m_config *config, const char *name_prefix,
|
|||
.co_index = config->num_opts,
|
||||
};
|
||||
|
||||
const void *optstruct_def = subopts->defaults;
|
||||
|
||||
if (subopts->prefix && subopts->prefix[0])
|
||||
name_prefix = subopts->prefix;
|
||||
if (!name_prefix)
|
||||
|
@ -546,16 +544,9 @@ static void add_sub_group(struct m_config *config, const char *name_prefix,
|
|||
.name = concat_name(config, name_prefix, opt->name),
|
||||
.opt = opt,
|
||||
.group_index = group_index,
|
||||
.default_data = &default_value,
|
||||
.is_hidden = !!opt->deprecation_message,
|
||||
};
|
||||
|
||||
if (opt->offset >= 0 && optstruct_def)
|
||||
co.default_data = (char *)optstruct_def + opt->offset;
|
||||
|
||||
if (opt->defval)
|
||||
co.default_data = opt->defval;
|
||||
|
||||
if (opt->type != &m_option_type_subconfig)
|
||||
MP_TARRAY_APPEND(config, config->opts, config->num_opts, co);
|
||||
}
|
||||
|
@ -571,8 +562,8 @@ static void add_sub_group(struct m_config *config, const char *name_prefix,
|
|||
const struct m_sub_options *new_subopts = opt->priv;
|
||||
|
||||
// Providing default structs in-place is not allowed.
|
||||
if (opt->offset >= 0 && optstruct_def) {
|
||||
void *ptr = (char *)optstruct_def + opt->offset;
|
||||
if (opt->offset >= 0 && subopts->defaults) {
|
||||
void *ptr = (char *)subopts->defaults + opt->offset;
|
||||
assert(!substruct_read_ptr(ptr));
|
||||
}
|
||||
|
||||
|
@ -672,6 +663,19 @@ struct m_config_option *m_config_get_co_index(struct m_config *config, int index
|
|||
return &config->opts[index];
|
||||
}
|
||||
|
||||
const void *m_config_get_co_default(const struct m_config *config,
|
||||
struct m_config_option *co)
|
||||
{
|
||||
if (co->opt->defval)
|
||||
return co->opt->defval;
|
||||
|
||||
const struct m_sub_options *subopt = config->groups[co->group_index].group;
|
||||
if (co->opt->offset >= 0 && subopt->defaults)
|
||||
return (char *)subopt->defaults + co->opt->offset;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *m_config_get_positional_option(const struct m_config *config, int p)
|
||||
{
|
||||
int pos = 0;
|
||||
|
@ -1077,8 +1081,11 @@ void m_config_print_option_list(const struct m_config *config, const char *name)
|
|||
MP_INFO(config, " (%s to %s)", min, max);
|
||||
}
|
||||
char *def = NULL;
|
||||
if (co->default_data)
|
||||
def = m_option_pretty_print(opt, co->default_data);
|
||||
const void *defptr = m_config_get_co_default(config, co);
|
||||
if (!defptr)
|
||||
defptr = &default_value;
|
||||
if (defptr)
|
||||
def = m_option_pretty_print(opt, defptr);
|
||||
if (def) {
|
||||
MP_INFO(config, " (default: %s)", def);
|
||||
talloc_free(def);
|
||||
|
|
|
@ -47,7 +47,6 @@ struct m_config_option {
|
|||
const char *name; // Full name (ie option-subopt)
|
||||
const struct m_option *opt; // Option description
|
||||
void *data; // Raw value of the option
|
||||
const void *default_data; // Raw default value
|
||||
};
|
||||
|
||||
// Config object
|
||||
|
@ -179,6 +178,8 @@ struct m_config_option *m_config_get_co(const struct m_config *config,
|
|||
|
||||
int m_config_get_co_count(struct m_config *config);
|
||||
struct m_config_option *m_config_get_co_index(struct m_config *config, int index);
|
||||
const void *m_config_get_co_default(const struct m_config *config,
|
||||
struct m_config_option *co);
|
||||
|
||||
// Return the n-th option by position. n==0 is the first option. If there are
|
||||
// less than (n + 1) options, return NULL.
|
||||
|
|
|
@ -3732,12 +3732,13 @@ static int mp_property_option_info(void *ctx, struct m_property *prop,
|
|||
struct m_config_option *co = m_config_get_co(mpctx->mconfig, key);
|
||||
if (!co)
|
||||
return M_PROPERTY_UNKNOWN;
|
||||
const struct m_option *opt = co->opt;
|
||||
|
||||
union m_option_value def = {0};
|
||||
if (co->default_data)
|
||||
memcpy(&def, co->default_data, co->opt->type->size);
|
||||
const void *def_ptr = m_config_get_co_default(mpctx->mconfig, co);
|
||||
if (def_ptr && opt->type->size > 0)
|
||||
memcpy(&def, def_ptr, opt->type->size);
|
||||
|
||||
const struct m_option *opt = co->opt;
|
||||
bool has_minmax =
|
||||
opt->type == &m_option_type_int ||
|
||||
opt->type == &m_option_type_int64 ||
|
||||
|
|
Loading…
Reference in New Issue