From 6a0021cf2044e2bc36883a63362cbc7657bf5fe0 Mon Sep 17 00:00:00 2001 From: Michael Hohmuth Date: Mon, 6 Jun 2011 22:49:07 +0000 Subject: FS#12132 patch 5: check_clauses: Optimizations. * There's no need to reset the buffer argument to check_against_clauses to 0 when it's not needed. We can always initialize str = buf and only change it on a RAM search hit. * Do not memset buffer to 0 -- it's sufficient to make sure the retrieved tag string is zero-terminated. * Factor out a call to check_virtual_tags from two branches of an if statement. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29981 a1c6a512-1295-4272-9138-f99709370657 --- apps/tagcache.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'apps/tagcache.c') diff --git a/apps/tagcache.c b/apps/tagcache.c index 629bf46aba..a3585feea5 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -993,28 +993,25 @@ static bool check_clauses(struct tagcache_search *tcs, { int seek; char buf[256]; - char *str; + char *str = buf; struct tagcache_search_clause *clause = clauses[i]; if (clause->type == clause_logical_or) break; /* all conditions before logical-or satisfied -- stop processing clauses */ -#ifdef HAVE_TC_RAMCACHE - str = NULL; + seek = check_virtual_tags(clause->tag, tcs->idx_id, idx); +#ifdef HAVE_TC_RAMCACHE if (tcs->ramsearch) { struct tagfile_entry *tfe; - seek = check_virtual_tags(clause->tag, tcs->idx_id, idx); - if (!TAGCACHE_IS_NUMERIC(clause->tag)) { if (clause->tag == tag_filename) { retrieve(tcs, idx, tag_filename, buf, sizeof buf); - str = buf; } else { @@ -1027,11 +1024,7 @@ static bool check_clauses(struct tagcache_search *tcs, #endif { struct tagfile_entry tfe; - str = buf; - seek = check_virtual_tags(clause->tag, tcs->idx_id, idx); - - memset(buf, 0, sizeof buf); if (!TAGCACHE_IS_NUMERIC(clause->tag)) { int fd = tcs->idxfd[clause->tag]; @@ -1044,6 +1037,7 @@ static bool check_clauses(struct tagcache_search *tcs, } read(fd, str, tfe.tag_length); + str[tfe.tag_length] = '\0'; /* Check if entry has been deleted. */ if (str[0] == '\0') -- cgit v1.2.3