summaryrefslogtreecommitdiff
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)
398 398
399static int get_clause(int *condition) 399static int get_clause(int *condition)
400{ 400{
401 static const struct match get_clause_match[] = 401 /* one or two operator conditionals */
402 { 402 #define OPS2VAL(op1, op2) ((int)op1 << 8 | (int)op2)
403 {"=", clause_is}, 403 #define CLAUSE(op1, op2, symbol) {OPS2VAL(op1, op2), symbol }
404 {"==", clause_is}, 404
405 {"!=", clause_is_not}, 405 struct clause_symbol {int value;int symbol;};
406 {">", clause_gt}, 406 static const struct clause_symbol get_clause_match[] =
407 {">=", clause_gteq}, 407 {
408 {"<", clause_lt}, 408 CLAUSE('=', ' ', clause_is),
409 {"<=", clause_lteq}, 409 CLAUSE('=', '=', clause_is),
410 {"~", clause_contains}, 410 CLAUSE('!', '=', clause_is_not),
411 {"!~", clause_not_contains}, 411 CLAUSE('>', ' ', clause_gt),
412 {"^", clause_begins_with}, 412 CLAUSE('>', '=', clause_gteq),
413 {"!^", clause_not_begins_with}, 413 CLAUSE('<', ' ', clause_lt),
414 {"$", clause_ends_with}, 414 CLAUSE('<', '=', clause_lteq),
415 {"!$", clause_not_ends_with}, 415 CLAUSE('~', ' ', clause_contains),
416 {"@", clause_oneof} 416 CLAUSE('!', '~', clause_not_contains),
417 CLAUSE('^', ' ', clause_begins_with),
418 CLAUSE('!', '^', clause_not_begins_with),
419 CLAUSE('$', ' ', clause_ends_with),
420 CLAUSE('!', '$', clause_not_ends_with),
421 CLAUSE('@', ' ', clause_oneof)
417 }; 422 };
418 423
419 char buf[4];
420 unsigned int i;
421
422 /* Find the start. */ 424 /* Find the start. */
423 while (*strp == ' ' && *strp != '\0') 425 while (*strp == ' ' && *strp != '\0')
424 strp++; 426 strp++;
@@ -426,18 +428,16 @@ static int get_clause(int *condition)
426 if (*strp == '\0') 428 if (*strp == '\0')
427 return 0; 429 return 0;
428 430
429 for (i = 0; i < sizeof(buf)-1; i++) 431 char op1 = strp[0];
430 { 432 char op2 = strp[1];
431 if (*strp == '\0' || *strp == ' ') 433 if (op2 == '"') /*allow " to end a single op conditional */
432 break ; 434 op2 = ' ';
433 buf[i] = *strp; 435
434 strp++; 436 int value = OPS2VAL(op1, op2);
435 }
436 buf[i] = '\0';
437 437
438 for (i = 0; i < ARRAYLEN(get_clause_match); i++) 438 for (unsigned int i = 0; i < ARRAYLEN(get_clause_match); i++)
439 { 439 {
440 if (!strcasecmp(buf, get_clause_match[i].str)) 440 if (value == get_clause_match[i].value)
441 { 441 {
442 *condition = get_clause_match[i].symbol; 442 *condition = get_clause_match[i].symbol;
443 return 1; 443 return 1;
@@ -445,6 +445,8 @@ static int get_clause(int *condition)
445 } 445 }
446 446
447 return 0; 447 return 0;
448#undef OPS2VAL
449#undef CLAUSE
448} 450}
449 451
450static bool read_clause(struct tagcache_search_clause *clause) 452static bool read_clause(struct tagcache_search_clause *clause)