diff options
author | William Wilgus <wilgus.william@gmail.com> | 2024-09-25 00:09:53 -0400 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2024-09-25 01:03:11 -0400 |
commit | a0e95c888d84bf20c73e7b1e8a274749b1bcdc94 (patch) | |
tree | 75cfd446838ee7de2cb8f484ee43d791fb697d7d | |
parent | ffebb9e244900924f48496989318486e583d910e (diff) | |
download | rockbox-a0e95c888d.tar.gz rockbox-a0e95c888d.zip |
[Feature/Bugfix] Tagtree use insert context to speed up adding tracks to playlist
I forgot we had duplicated code between playlist.c and tagtree.c this saves
a bit of space and should speed up adding tracks a bit
further I noticed a buf here where there was the potential to return without closing
the opened track search
Change-Id: I15ed8447fc4fe13de5bfeb9fbb59b151e2fbf36a
-rw-r--r-- | apps/tagtree.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/apps/tagtree.c b/apps/tagtree.c index 1a49936f45..267fa4fba7 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c @@ -2205,34 +2205,35 @@ static bool insert_all_playlist(struct tree_context *c, bool fill_randomly = false; bool *rand_bool_array = NULL; char buf[MAX_PATH]; + struct playlist_insert_context context; cpu_boost(true); + if (!tagcache_search(&tcs, tag_filename)) { splash(HZ, ID2P(LANG_TAGCACHE_BUSY)); cpu_boost(false); return false; - } + } /* NOTE: you need to close this search before returning */ - if (playlist == NULL && position == PLAYLIST_REPLACE) + if (playlist == NULL) { - if (playlist_remove_all_tracks(NULL) == 0) - position = PLAYLIST_INSERT_LAST; - else + if (playlist_insert_context_create(NULL, &context, position, queue, false) < 0) { + tagcache_search_finish(&tcs); cpu_boost(false); return false; } } - else if (playlist != NULL) + else { if (new_playlist) fd = open_utf8(playlist, O_CREAT|O_WRONLY|O_TRUNC); else fd = open(playlist, O_CREAT|O_WRONLY|O_APPEND, 0666); - if(fd < 0) { + tagcache_search_finish(&tcs); cpu_boost(false); return false; } @@ -2249,6 +2250,7 @@ static bool insert_all_playlist(struct tree_context *c, if (slots_remaining <= 0) { logf("Playlist has no space remaining"); + tagcache_search_finish(&tcs); cpu_boost(false); return false; } @@ -2332,7 +2334,7 @@ static bool insert_all_playlist(struct tree_context *c, } } - if (playlist_insert_track(NULL, buf, position, queue, false) < 0) { + if (playlist_insert_context_add(&context, buf) < 0) { logf("playlist_insert_track failed"); exit_loop_now = true; break; @@ -2350,10 +2352,12 @@ static bool insert_all_playlist(struct tree_context *c, if (exit_loop_now) break; } + if (playlist == NULL) - playlist_sync(NULL); + playlist_insert_context_release(&context); else close(fd); + tagcache_search_finish(&tcs); cpu_boost(false); |