1
0
Fork 0
forked from len0rd/rockbox

[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
This commit is contained in:
William Wilgus 2024-09-25 00:09:53 -04:00 committed by William Wilgus
parent ffebb9e244
commit a0e95c888d

View file

@ -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);