]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Simplify row_belongs_to_score_table().
authorAndre Noll <maan@tuebingen.mpg.de>
Thu, 10 Mar 2022 19:27:08 +0000 (20:27 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 17 Oct 2022 18:36:21 +0000 (20:36 +0200)
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.

afs.h
mood.c
playlist.c
score.c

diff --git a/afs.h b/afs.h
index 1c54a1bdc9a820fd2801a740432b4098deccd2f2..52aad791be3b33df12100ad4ce1b694170837baa 100644 (file)
--- 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 597ca650b7e01b621c567f8c7f6bf45af0d0c780..66024db6add623716b428edd0263847705bc80e9 100644 (file)
--- 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);
 }
 
index 5cfe1a75196d5baf446507b21ee551044ecf446a..65c2148a9ee7c92a432e15e622f080f552c4fbce 100644 (file)
@@ -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 19cfef86212dd867d6dea3c924a0f40ca897a2cd..c7a2411b4282e5c224b8692ab7428f7fff75f3b4 100644 (file)
--- 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)