From: Ingo Bürk Date: Thu, 26 Mar 2015 18:27:28 +0000 (+0100) Subject: Return in child parsing as soon as the match was made. X-Git-Tag: 4.10.1~13^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;ds=sidebyside;h=6adc7e8bfbdd6c6b646bd893eb6439090e697cf5;hp=ad31b13cb66f65431189f0ade323b9634cc26e8c;p=i3%2Fi3 Return in child parsing as soon as the match was made. As soon as we found the current key for which the value should be handled we can return from the function to save some string comparisons. --- diff --git a/i3bar/src/child.c b/i3bar/src/child.c index 3de754e7..20fbd9b0 100644 --- a/i3bar/src/child.c +++ b/i3bar/src/child.c @@ -181,10 +181,13 @@ static int stdin_boolean(void *context, int val) { parser_ctx *ctx = context; if (strcasecmp(ctx->last_map_key, "urgent") == 0) { ctx->block.urgent = val; + return 1; } if (strcasecmp(ctx->last_map_key, "separator") == 0) { ctx->block.no_separator = !val; + return 1; } + return 1; } @@ -192,15 +195,19 @@ static int stdin_string(void *context, const unsigned char *val, size_t len) { parser_ctx *ctx = context; if (strcasecmp(ctx->last_map_key, "full_text") == 0) { ctx->block.full_text = i3string_from_markup_with_length((const char *)val, len); + return 1; } if (strcasecmp(ctx->last_map_key, "short_text") == 0) { ctx->block.short_text = i3string_from_markup_with_length((const char *)val, len); + return 1; } if (strcasecmp(ctx->last_map_key, "color") == 0) { sasprintf(&(ctx->block.color), "%.*s", len, val); + return 1; } if (strcasecmp(ctx->last_map_key, "markup") == 0) { ctx->block.is_markup = (len == strlen("pango") && !strncasecmp((const char *)val, "pango", strlen("pango"))); + return 1; } if (strcasecmp(ctx->last_map_key, "align") == 0) { if (len == strlen("center") && !strncmp((const char *)val, "center", strlen("center"))) { @@ -210,24 +217,30 @@ static int stdin_string(void *context, const unsigned char *val, size_t len) { } else { ctx->block.align = ALIGN_LEFT; } - } else if (strcasecmp(ctx->last_map_key, "min_width") == 0) { + return 1; + } + if (strcasecmp(ctx->last_map_key, "min_width") == 0) { char *copy = (char *)malloc(len + 1); strncpy(copy, (const char *)val, len); copy[len] = 0; ctx->block.min_width_str = copy; + return 1; } if (strcasecmp(ctx->last_map_key, "name") == 0) { char *copy = (char *)malloc(len + 1); strncpy(copy, (const char *)val, len); copy[len] = 0; ctx->block.name = copy; + return 1; } if (strcasecmp(ctx->last_map_key, "instance") == 0) { char *copy = (char *)malloc(len + 1); strncpy(copy, (const char *)val, len); copy[len] = 0; ctx->block.instance = copy; + return 1; } + return 1; } @@ -235,10 +248,13 @@ static int stdin_integer(void *context, long long val) { parser_ctx *ctx = context; if (strcasecmp(ctx->last_map_key, "min_width") == 0) { ctx->block.min_width = (uint32_t)val; + return 1; } if (strcasecmp(ctx->last_map_key, "separator_block_width") == 0) { ctx->block.sep_block_width = (uint32_t)val; + return 1; } + return 1; }