From: Ran Benita Date: Fri, 24 Feb 2012 08:46:41 +0000 (+0200) Subject: Don't cache loaded rules files X-Git-Tag: xkbcommon-0.2.0~760^2~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3216ecc07f5fb634a35f7d9ed9ef8e3d7f4494d5;p=platform%2Fupstream%2Flibxkbcommon.git Don't cache loaded rules files This needlessly occupies memory for the lifetime of the library, and does not make a noticeable difference otherwise. This rules file won't be loaded more than once in most cases anyway, so just load it again when it happens. Signed-off-by: Ran Benita --- diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c index 4298e60..e079d60 100644 --- a/src/xkbcomp/xkbcomp.c +++ b/src/xkbcomp/xkbcomp.c @@ -77,36 +77,23 @@ XkbComponentsFromRules(const char *rules, const XkbRF_VarDefsPtr defs) { FILE *rulesFile = NULL; char *rulesPath = NULL; - static XkbRF_RulesPtr loaded = NULL; - static char *cached_name = NULL; + XkbRF_RulesPtr loaded = NULL; struct xkb_component_names * names = NULL; - if (!cached_name || strcmp(rules, cached_name) != 0) { - if (loaded) - XkbcRF_Free(loaded); - loaded = NULL; - free(cached_name); - cached_name = NULL; + rulesFile = XkbFindFileInPath(rules, XkmRulesFile, &rulesPath); + if (!rulesFile) { + ERROR("could not find \"%s\" rules in XKB path\n", rules); + return NULL; } - if (!loaded) { - rulesFile = XkbFindFileInPath(rules, XkmRulesFile, &rulesPath); - if (!rulesFile) { - ERROR("could not find \"%s\" rules in XKB path\n", rules); - goto out; - } - - if (!(loaded = _XkbTypedCalloc(1, XkbRF_RulesRec))) { - ERROR("failed to allocate XKB rules\n"); - goto unwind_file; - } - - if (!XkbcRF_LoadRules(rulesFile, loaded)) { - ERROR("failed to load XKB rules \"%s\"\n", rulesPath); - goto unwind_file; - } + if (!(loaded = _XkbTypedCalloc(1, XkbRF_RulesRec))) { + ERROR("failed to allocate XKB rules\n"); + goto unwind_file; + } - cached_name = strdup(rules); + if (!XkbcRF_LoadRules(rulesFile, loaded)) { + ERROR("failed to load XKB rules \"%s\"\n", rulesPath); + goto unwind_file; } if (!(names = _XkbTypedCalloc(1, struct xkb_component_names))) { @@ -127,10 +114,10 @@ XkbComponentsFromRules(const char *rules, const XkbRF_VarDefsPtr defs) } unwind_file: + XkbcRF_Free(loaded); if (rulesFile) fclose(rulesFile); free(rulesPath); -out: return names; }