1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-29 02:22:19 +00:00

player/command: optimize duplicated property search in command_init

Would be better to search the other way around, because options list is
bigger than property list, but with minimal changes this is good enough.
Both are relatively small tho and the only reason for this micro
optimization is to increase the fuzzing throughput.
This commit is contained in:
Kacper Michajłow 2024-03-23 04:07:30 +01:00 committed by sfan5
parent bcab45149d
commit 12077b7f37

View File

@ -7060,6 +7060,11 @@ void command_uninit(struct MPContext *mpctx)
mpctx->command_ctx = NULL;
}
static int str_compare(const void *a, const void *b)
{
return strcmp(*(const char **)a, *(const char **)b);
}
void command_init(struct MPContext *mpctx)
{
struct command_ctx *ctx = talloc(NULL, struct command_ctx);
@ -7074,6 +7079,11 @@ void command_init(struct MPContext *mpctx)
talloc_zero_array(ctx, struct m_property, num_base + num_opts + 1);
memcpy(ctx->properties, mp_properties_base, sizeof(mp_properties_base));
const char **prop_names = talloc_array(NULL, const char *, num_base);
for (int i = 0; i < num_base; ++i)
prop_names[i] = mp_properties_base[i].name;
qsort(prop_names, num_base, sizeof(const char *), str_compare);
int count = num_base;
for (int n = 0; n < num_opts; n++) {
struct m_config_option *co = m_config_get_co_index(mpctx->mconfig, n);
@ -7107,7 +7117,7 @@ void command_init(struct MPContext *mpctx)
}
// The option might be covered by a manual property already.
if (m_property_list_find(ctx->properties, prop.name))
if (bsearch(&prop.name, prop_names, num_base, sizeof(const char *), str_compare))
continue;
ctx->properties[count++] = prop;
@ -7115,6 +7125,7 @@ void command_init(struct MPContext *mpctx)
node_init(&ctx->udata, MPV_FORMAT_NODE_MAP, NULL);
talloc_steal(ctx, ctx->udata.u.list);
talloc_free(prop_names);
}
static void command_event(struct MPContext *mpctx, int event, void *arg)