Cut down on continuous opening/closing of config file - keep it

cached
This commit is contained in:
twinaphex 2015-02-21 09:41:29 +01:00
parent 7268eab3e8
commit a36e2d2a30
2 changed files with 15 additions and 32 deletions

View File

@ -19,7 +19,6 @@
#include "input_overlay.h" #include "input_overlay.h"
#include "../driver.h" #include "../driver.h"
#include "../general.h" #include "../general.h"
#include <file/config_file.h>
#include <compat/posix_string.h> #include <compat/posix_string.h>
#include "input_common.h" #include "input_common.h"
#include <file/file_path.h> #include <file/file_path.h>
@ -523,17 +522,9 @@ static bool input_overlay_resolve_targets(struct overlay *ol,
bool input_overlay_load_overlays_resolve_iterate(input_overlay_t *ol) bool input_overlay_load_overlays_resolve_iterate(input_overlay_t *ol)
{ {
bool not_done = true; bool not_done = true;
config_file_t *conf = NULL;
if (!ol) if (!ol)
return false; return false;
conf = config_file_new(ol->overlay_path);
if (!conf)
{
RARCH_ERR("Failed to load config file: %s.\n", ol->overlay_path);
return false;
}
not_done = ol->pos < ol->size; not_done = ol->pos < ol->size;
@ -551,11 +542,8 @@ bool input_overlay_load_overlays_resolve_iterate(input_overlay_t *ol)
ol->pos += 1; ol->pos += 1;
config_file_free(conf);
return true; return true;
error: error:
config_file_free(conf);
ol->state = OVERLAY_STATUS_DEFERRED_ERROR; ol->state = OVERLAY_STATUS_DEFERRED_ERROR;
return false; return false;
@ -564,17 +552,9 @@ error:
bool input_overlay_load_overlays_iterate(input_overlay_t *ol) bool input_overlay_load_overlays_iterate(input_overlay_t *ol)
{ {
bool not_done = true; bool not_done = true;
config_file_t *conf = NULL;
if (!ol) if (!ol)
return false; return false;
conf = config_file_new(ol->overlay_path);
if (!conf)
{
RARCH_ERR("Failed to load config file: %s.\n", ol->overlay_path);
return false;
}
not_done = ol->pos < ol->size; not_done = ol->pos < ol->size;
@ -585,7 +565,7 @@ bool input_overlay_load_overlays_iterate(input_overlay_t *ol)
return true; return true;
} }
if (!input_overlay_load_overlay(ol, conf, if (!input_overlay_load_overlay(ol, ol->conf,
ol->overlay_path, &ol->overlays[ol->pos], ol->pos)) ol->overlay_path, &ol->overlays[ol->pos], ol->pos))
{ {
RARCH_ERR("[Overlay]: Failed to load overlay #%u.\n", (unsigned)ol->pos); RARCH_ERR("[Overlay]: Failed to load overlay #%u.\n", (unsigned)ol->pos);
@ -594,11 +574,8 @@ bool input_overlay_load_overlays_iterate(input_overlay_t *ol)
ol->pos += 1; ol->pos += 1;
config_file_free(conf);
return true; return true;
error: error:
config_file_free(conf);
ol->state = OVERLAY_STATUS_DEFERRED_ERROR; ol->state = OVERLAY_STATUS_DEFERRED_ERROR;
return false; return false;
@ -608,20 +585,19 @@ bool input_overlay_load_overlays(input_overlay_t *ol)
{ {
size_t i; size_t i;
unsigned overlays = 0; unsigned overlays = 0;
config_file_t *conf = NULL;
if (!ol) if (!ol)
return false; return false;
conf = config_file_new(ol->overlay_path); ol->conf = config_file_new(ol->overlay_path);
if (!conf) if (!ol->conf)
{ {
RARCH_ERR("Failed to load config file: %s.\n", ol->overlay_path); RARCH_ERR("Failed to load config file: %s.\n", ol->overlay_path);
return false; return false;
} }
if (!config_get_uint(conf, "overlays", &overlays)) if (!config_get_uint(ol->conf, "overlays", &overlays))
{ {
RARCH_ERR("overlays variable not defined in config.\n"); RARCH_ERR("overlays variable not defined in config.\n");
goto error; goto error;
@ -636,14 +612,12 @@ bool input_overlay_load_overlays(input_overlay_t *ol)
ol->size = overlays; ol->size = overlays;
ol->pos = 0; ol->pos = 0;
ol->state = OVERLAY_STATUS_DEFERRED_LOADING;
config_file_free(conf); ol->state = OVERLAY_STATUS_DEFERRED_LOADING;
return true; return true;
error: error:
config_file_free(conf);
ol->state = OVERLAY_STATUS_DEFERRED_ERROR; ol->state = OVERLAY_STATUS_DEFERRED_ERROR;
return false; return false;
@ -679,6 +653,10 @@ bool input_overlay_new_done(input_overlay_t *ol)
ol->state = OVERLAY_STATUS_ALIVE; ol->state = OVERLAY_STATUS_ALIVE;
if (ol->conf)
config_file_free(ol->conf);
ol->conf = NULL;
return true; return true;
} }
@ -1027,6 +1005,9 @@ void input_overlay_free(input_overlay_t *ol)
if (ol->iface) if (ol->iface)
ol->iface->enable(ol->iface_data, false); ol->iface->enable(ol->iface_data, false);
if (ol->conf)
config_file_free(ol->conf);
ol->conf = NULL;
free(ol->overlay_path); free(ol->overlay_path);
free(ol); free(ol);
} }

View File

@ -17,10 +17,11 @@
#ifndef INPUT_OVERLAY_H__ #ifndef INPUT_OVERLAY_H__
#define INPUT_OVERLAY_H__ #define INPUT_OVERLAY_H__
#include <stdint.h>
#include <boolean.h> #include <boolean.h>
#include "../libretro.h" #include "../libretro.h"
#include "../gfx/image/image.h" #include "../gfx/image/image.h"
#include <stdint.h> #include <file/config_file.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -140,6 +141,7 @@ struct input_overlay
size_t index; size_t index;
size_t size; size_t size;
size_t pos; size_t pos;
config_file_t *conf;
unsigned next_index; unsigned next_index;
char *overlay_path; char *overlay_path;