From bce7742745e23e4437e4c0f840d7bc14f7cedcf0 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 10 Apr 2018 17:40:29 +0200 Subject: [PATCH] Create playlist_cached functions inside playlist.c --- menu/menu_driver.c | 12 +++--------- playlist.c | 24 ++++++++++++++++++++++++ playlist.h | 6 ++++++ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/menu/menu_driver.c b/menu/menu_driver.c index dde5ee212b..403ce0d617 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -182,9 +182,6 @@ static bool menu_driver_pending_shutdown = false; /* Are we binding a button inside the menu? */ static bool menu_driver_is_binding = false; -/* The currently active playlist that we are using inside the menu */ -static playlist_t *menu_driver_playlist = NULL; - static menu_handle_t *menu_driver_data = NULL; static const menu_ctx_driver_t *menu_driver_ctx = NULL; static void *menu_userdata = NULL; @@ -1881,9 +1878,7 @@ bool menu_driver_ctl(enum rarch_menu_ctl_state state, void *data) menu_driver_pending_shutdown = true; break; case RARCH_MENU_CTL_PLAYLIST_FREE: - if (menu_driver_playlist) - playlist_free(menu_driver_playlist); - menu_driver_playlist = NULL; + playlist_free_cached(); break; case RARCH_MENU_CTL_FIND_DRIVER: { @@ -1930,8 +1925,7 @@ bool menu_driver_ctl(enum rarch_menu_ctl_state state, void *data) const char *path = (const char*)data; if (string_is_empty(path)) return false; - menu_driver_playlist = playlist_init(path, - COLLECTION_SIZE); + playlist_init_cached(path, COLLECTION_SIZE); } break; case RARCH_MENU_CTL_PLAYLIST_GET: @@ -1939,7 +1933,7 @@ bool menu_driver_ctl(enum rarch_menu_ctl_state state, void *data) playlist_t **playlist = (playlist_t**)data; if (!playlist) return false; - *playlist = menu_driver_playlist; + *playlist = playlist_get_cached(); } break; case RARCH_MENU_CTL_SET_PREVENT_POPULATE: diff --git a/playlist.c b/playlist.c index 91d8ed032b..fba39fee5f 100644 --- a/playlist.c +++ b/playlist.c @@ -52,6 +52,7 @@ struct content_playlist char *conf_path; struct playlist_entry *entries; }; +static playlist_t *playlist_cached = NULL; typedef int (playlist_sort_fun_t)( const struct playlist_entry *a, @@ -554,6 +555,29 @@ end: return true; } +void playlist_free_cached(void) +{ + playlist_free(playlist_cached); + playlist_cached = NULL; +} + +playlist_t *playlist_get_cached(void) +{ + if (playlist_cached) + return playlist_cached; + return NULL; +} + +bool playlist_init_cached(const char *path, size_t size) +{ + playlist_t *playlist = playlist_init(path, size); + if (!playlist) + return false; + + playlist_cached = playlist; + return true; +} + /** * playlist_init: * @path : Path to playlist contents file. diff --git a/playlist.h b/playlist.h index a130df23c8..d3e8ef1176 100644 --- a/playlist.h +++ b/playlist.h @@ -129,6 +129,12 @@ void playlist_write_file(playlist_t *playlist); void playlist_qsort(playlist_t *playlist); +void playlist_free_cached(void); + +playlist_t *playlist_get_cached(void); + +bool playlist_init_cached(const char *path, size_t size); + RETRO_END_DECLS #endif