summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-05-21 13:45:06 +0200
committerwm4 <wm4@nowhere>2018-05-24 19:56:35 +0200
commit816ad035191970decb17086f5c011edffc257b6c (patch)
tree9a5be112d6ff6cb585460d20d4e89c0724b1775f
parent3f061dd62912728bf152c06e7c27b43a3cef312d (diff)
downloadmpv-816ad035191970decb17086f5c011edffc257b6c.tar.bz2
mpv-816ad035191970decb17086f5c011edffc257b6c.tar.xz
m_config: remove extra default_data field
Just wastes memory (a few KB, because there are so many options).
-rw-r--r--options/m_config.c39
-rw-r--r--options/m_config.h3
-rw-r--r--player/command.c7
3 files changed, 29 insertions, 20 deletions
diff --git a/options/m_config.c b/options/m_config.c
index c6f4325287..e17803d023 100644
--- a/options/m_config.c
+++ b/options/m_config.c
@@ -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);
diff --git a/options/m_config.h b/options/m_config.h
index 8a8dba8461..19da75e83c 100644
--- a/options/m_config.h
+++ b/options/m_config.h
@@ -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.
diff --git a/player/command.c b/player/command.c
index 629ff234e2..e836b3ef21 100644
--- a/player/command.c
+++ b/player/command.c
@@ -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 ||