From ed7b668ad79fdcde7bc8abddd46f721d5b232d04 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sat, 11 Jul 2009 17:13:04 +0200 Subject: [PATCH] Scoring performance enhancements. The old scoring code computed the afsi, afhi, and the path of the audio file for each item of the mood, which is unnecessary. This patch moves these computations from get_item_score() into compute_mood_score() so that afsi, afhi and path are only computed once per audio file. As a result, get_item_score() can no longer fail, so we may skip the checks for negative return values. --- mood.c | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/mood.c b/mood.c index 26d68dc5..f3ce9e0a 100644 --- a/mood.c +++ b/mood.c @@ -107,28 +107,17 @@ static uint64_t int_sqrt(uint64_t x) return res; } -/* returns 1 if row matches score item, 0 if not, negative on errors */ -static int get_item_score(const struct osl_row *row, struct mood_item *item, - long *score, long *score_arg_sum) +/* returns 1 if row matches score item, 0 if not. */ +static int get_item_score(struct mood_item *item, const struct afs_info *afsi, + const struct afh_info *afhi, const char *path, long *score, + long *score_arg_sum) { - struct afs_info afsi; - struct afh_info afhi; - char *path; int ret, match = 1; *score_arg_sum += item->random_score? 100 : PARA_ABS(item->score_arg); ret = 100; if (item->method) { - ret = get_afsi_of_row(row, &afsi); - if (ret< 0) - return ret; - ret = get_afhi_of_row(row, &afhi); - if (ret< 0) - return ret; - ret = get_audio_file_path_of_row(row, &path); - if (ret< 0) - return ret; - ret = item->method->score_function(path, &afsi, &afhi, + ret = item->method->score_function(path, afsi, afhi, item->parser_data); if ((ret < 0 && !item->logical_not) || (ret >= 0 && item->logical_not)) match = 0; /* no match */ @@ -147,24 +136,32 @@ static int compute_mood_score(const struct osl_row *aft_row, struct mood *m, struct mood_item *item; int ret, match = 0; long score_arg_sum = 0, score = 0, item_score; + struct afs_info afsi; + struct afh_info afhi; + char *path; if (!m) return -E_NO_MOOD; + ret = get_afsi_of_row(aft_row, &afsi); + if (ret< 0) + return ret; + ret = get_afhi_of_row(aft_row, &afhi); + if (ret< 0) + return ret; + ret = get_audio_file_path_of_row(aft_row, &path); + if (ret< 0) + return ret; /* reject audio file if it matches any entry in the deny list */ list_for_each_entry(item, &m->deny_list, mood_item_node) { - ret = get_item_score(aft_row, item, &item_score, + ret = get_item_score(item, &afsi, &afhi, path, &item_score, &score_arg_sum); - if (ret < 0) - return ret; if (ret > 0) /* not admissible */ return 0; score += item_score; } list_for_each_entry(item, &m->accept_list, mood_item_node) { - ret = get_item_score(aft_row, item, &item_score, + ret = get_item_score(item, &afsi, &afhi, path, &item_score, &score_arg_sum); - if (ret < 0) - return ret; if (ret == 0) continue; match = 1; @@ -174,10 +171,8 @@ static int compute_mood_score(const struct osl_row *aft_row, struct mood *m, if (!match && !list_empty(&m->accept_list)) return 0; list_for_each_entry(item, &m->score_list, mood_item_node) { - ret = get_item_score(aft_row, item, &item_score, + ret = get_item_score(item, &afsi, &afhi, path, &item_score, &score_arg_sum); - if (ret < 0) - return ret; score += item_score; } if (score_arg_sum) -- 2.30.2