Permalink
Browse files

Refactor directory listing to greatly optimize sorting.

  • Loading branch information...
1 parent 031e37d commit 14f7f641f3d1ab15850b2adb15afdd20859cee8b @Themaister committed Jun 23, 2012
Showing with 140 additions and 125 deletions.
  1. +18 −15 driver.c
  2. +24 −7 file.h
  3. +83 −91 file_path.c
  4. +1 −2 general.h
  5. +14 −10 retroarch.c
View
@@ -484,28 +484,31 @@ static void deinit_filter(void)
#endif
#ifdef HAVE_XML
+static void deinit_shader_dir(void)
+{
+ // It handles NULL, no worries :D
+ dir_list_free(g_extern.shader_dir.list);
+ g_extern.shader_dir.list = NULL;
+ g_extern.shader_dir.ptr = 0;
+}
+
static void init_shader_dir(void)
{
if (!*g_settings.video.shader_dir)
return;
- g_extern.shader_dir.elems = dir_list_new(g_settings.video.shader_dir, "shader", false);
- g_extern.shader_dir.size = dir_list_size(g_extern.shader_dir.elems);
- g_extern.shader_dir.ptr = 0;
-
- dir_list_sort(g_extern.shader_dir.elems, false);
+ g_extern.shader_dir.list = dir_list_new(g_settings.video.shader_dir, "shader", false);
+ if (g_extern.shader_dir.list->size == 0)
+ {
+ deinit_shader_dir();
+ return;
+ }
- for (unsigned i = 0; i < g_extern.shader_dir.size; i++)
- RARCH_LOG("Found shader \"%s\"\n", g_extern.shader_dir.elems[i]);
-}
+ g_extern.shader_dir.ptr = 0;
+ dir_list_sort(g_extern.shader_dir.list, false);
-static void deinit_shader_dir(void)
-{
- // It handles NULL, no worries :D
- dir_list_free(g_extern.shader_dir.elems);
- g_extern.shader_dir.elems = NULL;
- g_extern.shader_dir.size = 0;
- g_extern.shader_dir.ptr = 0;
+ for (unsigned i = 0; i < g_extern.shader_dir.list->size; i++)
+ RARCH_LOG("Found shader \"%s\"\n", g_extern.shader_dir.list->elems[i].data);
}
#endif
View
31 file.h
@@ -36,13 +36,30 @@ void save_ram_file(const char *path, int type);
bool init_rom_file(enum rarch_game_type type);
-// Returns a NULL-terminated list of files in a directory with full paths.
-// If ext is NULL, any file will be picked.
-// If non-NULL, only files with extension ext are added.
-char **dir_list_new(const char *dir, const char *ext, bool include_dirs);
-size_t dir_list_size(char * const *dir_list);
-void dir_list_sort(char **dir_list, bool dir_first);
-void dir_list_free(char **dir_list);
+// Yep, this is C alright ;)
+union string_list_elem_attr
+{
+ bool b;
+ int i;
+ void *p;
+};
+
+struct string_list_elem
+{
+ char *data;
+ union string_list_elem_attr attr;
+};
+
+struct string_list
+{
+ struct string_list_elem *elems;
+ size_t size;
+ size_t cap;
+};
+
+struct string_list *dir_list_new(const char *dir, const char *ext, bool include_dirs);
+void dir_list_sort(struct string_list *list, bool dir_first);
+void dir_list_free(struct string_list *list);
bool path_is_directory(const char *path);
bool path_file_exists(const char *path);
Oops, something went wrong.

0 comments on commit 14f7f64

Please sign in to comment.