From d893da19294ad63f4e3fd035d6d36e24ce68e0ca Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Mon, 10 Feb 2025 12:55:26 -0500 Subject: [PATCH] tagtree.c get_tag() increase performance while its not a particularly hot path it still gets called upwards of 1000x on startup with a little pre processing we can make it faster than even the prior version check first letter before calling function move strlen check to after the case match Change-Id: I0108aaf9828501b57b0950fbc24cd478a9eeacc1 --- apps/tagtree.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/tagtree.c b/apps/tagtree.c index 984be58065..30c681029d 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c @@ -358,6 +358,7 @@ static int get_token_str(char *buf, int size) static int get_tag(int *tag) { + /* case insensitive matching ahead - these should all be lower case */ #define TAG_TABLE \ TAG_MATCH("lm", tag_virt_length_min) \ TAG_MATCH("ls", tag_virt_length_sec) \ @@ -433,12 +434,16 @@ static int get_tag(int *tag) } tagstr_len = strp - tagstr; + char first = tolower(*tagstr++); /* get the first letter elide cmp fn call */ + for (size_t i = 0; i < ARRAYLEN(get_tag_match); i++) { const char *match = get_tag_match[i]; - if ((ptrdiff_t)strlen(match) == tagstr_len) + + if (first == match[0] && strncasecmp(tagstr, match + 1, tagstr_len - 1) == 0) { - if (strncasecmp(tagstr, match, tagstr_len) == 0) + /* check for full match */ + if ((ptrdiff_t)strlen(match) == tagstr_len) { *tag = get_tag_symbol[i]; return 1;