Commit ca9829ea66667e479bb4008d3b9e92727f090d3e

Ran Benita 2012-02-24T09:59:25

Don't cache parsed files This needlessly occupies memory for the lifetime of the library, and does not make a noticeable difference otherwise. Instead, just parse the same file again when it happens. Signed-off-by: Ran Benita <ran234@gmail.com>

diff --git a/src/xkbcomp/misc.c b/src/xkbcomp/misc.c
index 92943a5..523614f 100644
--- a/src/xkbcomp/misc.c
+++ b/src/xkbcomp/misc.c
@@ -57,37 +57,31 @@ ProcessIncludeFile(IncludeStmt * stmt,
     char oldFile[1024] = {0};
     int oldLine = lineNum;
 
-    rtrn = XkbFindFileInCache(stmt->file, file_type, &stmt->path);
-    if (rtrn == NULL)
+    file = XkbFindFileInPath(stmt->file, file_type, &stmt->path);
+    if (file == NULL)
     {
-        /* file not in cache, open it, parse it and store it in cache for next
-           time. */
-        file = XkbFindFileInPath(stmt->file, file_type, &stmt->path);
-        if (file == NULL)
-        {
-            ERROR("Can't find file \"%s\" for %s include\n", stmt->file,
-                   XkbDirectoryForInclude(file_type));
-            return False;
-        }
-        if (scanFile)
-            strcpy(oldFile, scanFile);
-        else
-            memset(oldFile, 0, sizeof(oldFile));
-        oldLine = lineNum;
-        setScanState(stmt->file, 1);
-        if (debugFlags & 2)
-            INFO("About to parse include file %s\n", stmt->file);
-        /* parse the file */
-        if ((XKBParseFile(file, &rtrn) == 0) || (rtrn == NULL))
-        {
-            setScanState(oldFile, oldLine);
-            ERROR("Error interpreting include file \"%s\"\n", stmt->file);
-            fclose(file);
-            return False;
-        }
+        ERROR("Can't find file \"%s\" for %s include\n", stmt->file,
+                XkbDirectoryForInclude(file_type));
+        return False;
+    }
+    if (scanFile)
+        strcpy(oldFile, scanFile);
+    else
+        memset(oldFile, 0, sizeof(oldFile));
+    oldLine = lineNum;
+    setScanState(stmt->file, 1);
+    if (debugFlags & 2)
+        INFO("About to parse include file %s\n", stmt->file);
+    /* parse the file */
+    if ((XKBParseFile(file, &rtrn) == 0) || (rtrn == NULL))
+    {
+        setScanState(oldFile, oldLine);
+        ERROR("Error interpreting include file \"%s\"\n", stmt->file);
         fclose(file);
-        XkbAddFileToCache(stmt->file, file_type, stmt->path, rtrn);
+        return False;
     }
+    fclose(file);
+
     mapToUse = rtrn;
     if (stmt->map != NULL)
     {
diff --git a/src/xkbcomp/xkbpath.c b/src/xkbcomp/xkbpath.c
index 1b04a7c..0839f88 100644
--- a/src/xkbcomp/xkbpath.c
+++ b/src/xkbcomp/xkbpath.c
@@ -294,85 +294,6 @@ XkbDirectoryForInclude(unsigned type)
 
 /***====================================================================***/
 
-typedef struct _FileCacheEntry
-{
-    char *name;
-    unsigned type;
-    char *path;
-    void *data;
-    struct _FileCacheEntry *next;
-} FileCacheEntry;
-static FileCacheEntry *fileCache;
-
-/**
- * Add the file with the given name to the internal cache to avoid opening and
- * parsing the file multiple times. If a cache entry for the same name + type
- * is already present, the entry is overwritten and the data belonging to the
- * previous entry is returned.
- *
- * @parameter name The name of the file (e.g. evdev).
- * @parameter type Type of the file (XkbTypesIdx, ... or XkbSemanticsFile, ...)
- * @parameter path The full path to the file.
- * @parameter data Already parsed data.
- *
- * @return The data from the overwritten file or NULL.
- */
-void *
-XkbAddFileToCache(char *name, unsigned type, char *path, void *data)
-{
-    FileCacheEntry *entry;
-
-    for (entry = fileCache; entry != NULL; entry = entry->next)
-    {
-        if ((type == entry->type) && (uStringEqual(name, entry->name)))
-        {
-            void *old = entry->data;
-            WSGO("Replacing file cache entry (%s/%d)\n", name, type);
-            entry->path = path;
-            entry->data = data;
-            return old;
-        }
-    }
-    entry = uTypedAlloc(FileCacheEntry);
-    if (entry != NULL)
-    {
-        entry->name = name;
-        entry->type = type;
-        entry->path = path;
-        entry->data = data;
-        entry->next = fileCache;
-        fileCache = entry;
-    }
-    return NULL;
-}
-
-/**
- * Search for the given name + type in the cache.
- *
- * @parameter name The name of the file (e.g. evdev).
- * @parameter type Type of the file (XkbTypesIdx, ... or XkbSemanticsFile, ...)
- * @parameter pathRtrn Set to the full path of the given entry.
- *
- * @return the data from the cache entry or NULL if no matching entry was found.
- */
-void *
-XkbFindFileInCache(char *name, unsigned type, char **pathRtrn)
-{
-    FileCacheEntry *entry;
-
-    for (entry = fileCache; entry != NULL; entry = entry->next)
-    {
-        if ((type == entry->type) && (uStringEqual(name, entry->name)))
-        {
-            *pathRtrn = entry->path;
-            return entry->data;
-        }
-    }
-    return NULL;
-}
-
-/***====================================================================***/
-
 /**
  * Search for the given file name in the include directories.
  *
diff --git a/src/xkbcomp/xkbpath.h b/src/xkbcomp/xkbpath.h
index eef1fb2..488999e 100644
--- a/src/xkbcomp/xkbpath.h
+++ b/src/xkbcomp/xkbpath.h
@@ -39,17 +39,6 @@ extern FILE *XkbFindFileInPath(const char * /* name */ ,
                                char **  /* pathRtrn */
     );
 
-extern void *XkbAddFileToCache(char * /* name */ ,
-                               unsigned /* type */ ,
-                               char * /* path */ ,
-                               void *   /* data */
-    );
-
-extern void *XkbFindFileInCache(char * /* name */ ,
-                                unsigned /* type */ ,
-                                char ** /* pathRtrn */
-    );
-
 extern Bool XkbParseIncludeMap(char ** /* str_inout */ ,
                                char ** /* file_rtrn */ ,
                                char ** /* map_rtrn */ ,