From: Andre Noll Date: Thu, 10 Mar 2022 19:27:08 +0000 (+0100) Subject: Simplify row_belongs_to_score_table(). X-Git-Tag: v0.7.2~14^2~10 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=ebb53a6a2d300d33832ffa51aa8e1100c4d700e6;p=paraslash.git Simplify row_belongs_to_score_table(). This function was over-engineered because only one caller passed a non-NULL rank pointer without actually using the rank for anything other than printing it in a log message. So drop the rank parameter and adjust the callers and the log message accordingly. Moreover, the function returned int rather than bool to be able to also return an error code in case the osl lookup function fails. This should never happen though, because the only possible errors are invalid row or table pointers, and these indicate a bug. So abort in this case and let the function return bool. --- diff --git a/afs.h b/afs.h index 1c54a1bd..52aad791 100644 --- a/afs.h +++ b/afs.h @@ -241,7 +241,7 @@ int score_add(const struct osl_row *row, long score); int score_update(const struct osl_row *aft_row, long new_score); int score_delete(const struct osl_row *aft_row); int clear_score_table(void); -int row_belongs_to_score_table(const struct osl_row *aft_row, unsigned *rank); +bool row_belongs_to_score_table(const struct osl_row *aft_row); /* attribute */ void attribute_init(struct afs_table *t); diff --git a/mood.c b/mood.c index 597ca650..66024db6 100644 --- a/mood.c +++ b/mood.c @@ -455,23 +455,18 @@ static int delete_from_statistics_and_score_table(const struct osl_row *aft_row) } /** - * Delete one entry from the statistics and from the score table. + * Delete an audio file from the score table and update mood statistics. * - * \param aft_row The audio file which is no longer admissible. + * \param aft_row Identifies the row to delete. * - * \return Positive on success, negative on errors. + * \return Standard. * * \sa \ref score_delete(). */ static int mood_delete_audio_file(const struct osl_row *aft_row) { - int ret; - - ret = row_belongs_to_score_table(aft_row, NULL); - if (ret < 0) - return ret; - if (!ret) /* not admissible, nothing to do */ - return 1; + if (!row_belongs_to_score_table(aft_row)) + return 0; return delete_from_statistics_and_score_table(aft_row); } @@ -493,14 +488,10 @@ static int mood_update_audio_file(const struct osl_row *aft_row, int ret; bool is_admissible, was_admissible; struct afs_info afsi; - unsigned rank; if (!current_mood) return 1; /* nothing to do */ - ret = row_belongs_to_score_table(aft_row, &rank); - if (ret < 0) - return ret; - was_admissible = ret; + was_admissible = row_belongs_to_score_table(aft_row); is_admissible = mp_eval_row(aft_row, current_mood->parser_context); if (!was_admissible && !is_admissible) return 1; @@ -525,7 +516,7 @@ static int mood_update_audio_file(const struct osl_row *aft_row, percent = 100; else if (percent < 0) percent = 0; - PARA_DEBUG_LOG("moving from rank %u to %li%%\n", rank, percent); + PARA_DEBUG_LOG("moving to %li%%\n", percent); return score_update(aft_row, percent); } diff --git a/playlist.c b/playlist.c index 5cfe1a75..65c2148a 100644 --- a/playlist.c +++ b/playlist.c @@ -193,12 +193,8 @@ static int handle_audio_file_event(enum afs_events event, void *data) char *new_path; const struct osl_row *row = data; - if (event == AUDIO_FILE_RENAME) { - ret = row_belongs_to_score_table(row, NULL); - if (ret < 0) - return ret; - was_admissible = ret; - } + if (event == AUDIO_FILE_RENAME) + was_admissible = row_belongs_to_score_table(row); ret = get_audio_file_path_of_row(row, &new_path); if (ret < 0) return ret; @@ -234,7 +230,6 @@ static int handle_audio_file_event(enum afs_events event, void *data) int playlists_event_handler(enum afs_events event, __a_unused struct para_buffer *pb, void *data) { - int ret; struct afsi_change_event_data *aced = data; if (!current_playlist.name) @@ -246,10 +241,7 @@ int playlists_event_handler(enum afs_events event, case AUDIO_FILE_ADD: return handle_audio_file_event(event, data); case AUDIO_FILE_REMOVE: - ret = row_belongs_to_score_table(data, NULL); - if (ret < 0) - return ret; - if (!ret) + if (!row_belongs_to_score_table(data)) return 1; current_playlist.length--; return score_delete(data); diff --git a/score.c b/score.c index 19cfef86..c7a2411b 100644 --- a/score.c +++ b/score.c @@ -255,27 +255,20 @@ int score_delete(const struct osl_row *aft_row) * Find out whether an audio file is contained in the score table. * * \param aft_row The row of the audio file table. - * \param rank Result pointer * - * \return Positive, if \a aft_row belongs to the audio file table, - * zero if not, negative on errors. If \a aft_row was found, and \a rank - * is not \p NULL, the rank of \a aft_row is returned in \a rank. + * \return If the lookup operation fails for any other reason than "not found", + * the function aborts the current process (afs), since this is considered a + * fatal error that should never happen. */ -int row_belongs_to_score_table(const struct osl_row *aft_row, unsigned *rank) +bool row_belongs_to_score_table(const struct osl_row *aft_row) { struct osl_row *score_row; int ret = get_score_row_from_aft_row(aft_row, &score_row); if (ret == -OSL_ERRNO_TO_PARA_ERROR(E_OSL_RB_KEY_NOT_FOUND)) - return 0; - if (ret < 0) - return ret; - if (!rank) - return 1; - ret = osl(osl_get_rank(score_table, score_row, SCORECOL_SCORE, rank)); - if (ret < 0) - return ret; - return 1; + return false; + assert(ret >= 0); + return true; } static void score_close(void)