summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2024-03-23 04:07:30 +0100
committersfan5 <sfan5@live.de>2024-03-25 15:56:06 +0100
commit12077b7f37710d61bf5524bef7177f46157c896e (patch)
tree30130fc0800f8139d844d90c13fb6225d898a727
parentbcab45149dc16cfbe111ed8da1aefcbf32a535e2 (diff)
downloadmpv-12077b7f37710d61bf5524bef7177f46157c896e.tar.bz2
mpv-12077b7f37710d61bf5524bef7177f46157c896e.tar.xz
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.
-rw-r--r--player/command.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/player/command.c b/player/command.c
index 36a9afbb29..bcac0828e0 100644
--- a/player/command.c
+++ b/player/command.c
@@ -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)