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>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
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 */ ,