From a0e95c888d84bf20c73e7b1e8a274749b1bcdc94 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Wed, 25 Sep 2024 00:09:53 -0400 Subject: [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 --- apps/tagtree.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'apps/tagtree.c') 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); -- cgit v1.2.3