summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2022-02-27 15:42:24 -0500
committerWilliam Wilgus <wilgus.william@gmail.com>2022-02-28 06:35:11 -0500
commit045f52d475f57053329b90e97dba7deb1676b5ec (patch)
tree4d900d82273789f053395df0cb99fd5636b33a0c
parent1bcb1e39ee421c8e00fd84f0f278329e261560f1 (diff)
downloadrockbox-045f52d475f57053329b90e97dba7deb1676b5ec.tar.gz
rockbox-045f52d475f57053329b90e97dba7deb1676b5ec.zip
tagtree.c optmize clause operator parsing
makes WS after a clause conditional optional Change-Id: I335b5381fb788c19130aa8d57dfb18bb43a07c18
-rw-r--r--apps/tagtree.c60
1 files changed, 31 insertions, 29 deletions
diff --git a/apps/tagtree.c b/apps/tagtree.c
index 4db4a91cc7..9684d5424c 100644
--- a/apps/tagtree.c
+++ b/apps/tagtree.c
@@ -398,27 +398,29 @@ static int get_tag(int *tag)
static int get_clause(int *condition)
{
- static const struct match get_clause_match[] =
- {
- {"=", clause_is},
- {"==", clause_is},
- {"!=", clause_is_not},
- {">", clause_gt},
- {">=", clause_gteq},
- {"<", clause_lt},
- {"<=", clause_lteq},
- {"~", clause_contains},
- {"!~", clause_not_contains},
- {"^", clause_begins_with},
- {"!^", clause_not_begins_with},
- {"$", clause_ends_with},
- {"!$", clause_not_ends_with},
- {"@", clause_oneof}
+ /* one or two operator conditionals */
+ #define OPS2VAL(op1, op2) ((int)op1 << 8 | (int)op2)
+ #define CLAUSE(op1, op2, symbol) {OPS2VAL(op1, op2), symbol }
+
+ struct clause_symbol {int value;int symbol;};
+ static const struct clause_symbol get_clause_match[] =
+ {
+ CLAUSE('=', ' ', clause_is),
+ CLAUSE('=', '=', clause_is),
+ CLAUSE('!', '=', clause_is_not),
+ CLAUSE('>', ' ', clause_gt),
+ CLAUSE('>', '=', clause_gteq),
+ CLAUSE('<', ' ', clause_lt),
+ CLAUSE('<', '=', clause_lteq),
+ CLAUSE('~', ' ', clause_contains),
+ CLAUSE('!', '~', clause_not_contains),
+ CLAUSE('^', ' ', clause_begins_with),
+ CLAUSE('!', '^', clause_not_begins_with),
+ CLAUSE('$', ' ', clause_ends_with),
+ CLAUSE('!', '$', clause_not_ends_with),
+ CLAUSE('@', ' ', clause_oneof)
};
- char buf[4];
- unsigned int i;
-
/* Find the start. */
while (*strp == ' ' && *strp != '\0')
strp++;
@@ -426,18 +428,16 @@ static int get_clause(int *condition)
if (*strp == '\0')
return 0;
- for (i = 0; i < sizeof(buf)-1; i++)
- {
- if (*strp == '\0' || *strp == ' ')
- break ;
- buf[i] = *strp;
- strp++;
- }
- buf[i] = '\0';
+ char op1 = strp[0];
+ char op2 = strp[1];
+ if (op2 == '"') /*allow " to end a single op conditional */
+ op2 = ' ';
+
+ int value = OPS2VAL(op1, op2);
- for (i = 0; i < ARRAYLEN(get_clause_match); i++)
+ for (unsigned int i = 0; i < ARRAYLEN(get_clause_match); i++)
{
- if (!strcasecmp(buf, get_clause_match[i].str))
+ if (value == get_clause_match[i].value)
{
*condition = get_clause_match[i].symbol;
return 1;
@@ -445,6 +445,8 @@ static int get_clause(int *condition)
}
return 0;
+#undef OPS2VAL
+#undef CLAUSE
}
static bool read_clause(struct tagcache_search_clause *clause)