From 1d7123d83796182f851ccccaf056063955343718 Mon Sep 17 00:00:00 2001 From: Timo Teräs Date: Mon, 4 May 2020 21:45:11 +0300 Subject: rewrite option descriptors to be single string This reduces the number of relocations on PIE binaries, and also reduces the executable size. Parsing of the options is slightly sped up as only the exact matching option group parser is called. --- src/app_dot.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/app_dot.c') diff --git a/src/app_dot.c b/src/app_dot.c index d567e5a..548e6e3 100644 --- a/src/app_dot.c +++ b/src/app_dot.c @@ -24,15 +24,25 @@ struct dot_ctx { int installed_only : 1; }; -static int option_parse_applet(void *pctx, struct apk_db_options *dbopts, int optch, const char *optarg) +enum { + OPT_DOT_errors, + OPT_DOT_installed, +}; + +static const char option_desc[] = + APK_OPTAPPLET + APK_OPT1n("errors") + APK_OPT1n("installed"); + +static int option_parse_applet(void *pctx, struct apk_db_options *dbopts, int opt, const char *optarg) { struct dot_ctx *ctx = (struct dot_ctx *) pctx; - switch (optch) { - case 0x10000: + switch (opt) { + case OPT_DOT_errors: ctx->errors_only = 1; break; - case 0x10001: + case OPT_DOT_installed: ctx->installed_only = 1; dbopts->open_flags &= ~APK_OPENF_NO_INSTALLED; break; @@ -42,15 +52,8 @@ static int option_parse_applet(void *pctx, struct apk_db_options *dbopts, int op return 0; } -static const struct apk_option options_applet[] = { - { 0x10000, "errors" }, - { 0x10001, "installed" }, -}; - static const struct apk_option_group optgroup_applet = { - .name = "Dot", - .options = options_applet, - .num_options = ARRAY_SIZE(options_applet), + .desc = option_desc, .parse = option_parse_applet, }; -- cgit v1.2.3-60-g2f50