output: cache the mapped file names

Don't repeatedly call malloc/free for each call to map_file_name.

* bootstrap.conf: We need hash-map.
* src/files.h, src/files.c (map_file_name): The caller must not free
the result.
Adjust callers.
(mapped_dir_prefix, spec_mapped_header_file): Remove.
* src/files.c
(map_file_name): Rename as...
(map_file_name_alloc): this.
(mapped_files, map_file_name, string_equals, string_hash, string_free):
New.
This commit is contained in:
Akim Demaille
2021-02-25 08:31:50 +01:00
parent b96528b48c
commit f6eb1ac87b
7 changed files with 94 additions and 48 deletions

View File

@@ -53,15 +53,9 @@ extern char *spec_xml_file;
/* File name specified with --header. */
extern char *spec_header_file;
/* File name specified with --header, adjusted for mapped prefixes. */
extern char *spec_mapped_header_file;
/* Directory prefix of output file names. */
extern char *dir_prefix;
/* Directory prefix of output file name, adjusted for mapped prefixes. */
extern char *mapped_dir_prefix;
/* The file name as given on the command line.
Not named "input_file" because Flex uses this name for an argument,
and therefore GCC warns about a name clash. */
@@ -94,7 +88,10 @@ FILE *xfopen (const char *name, char const *mode);
void xfclose (FILE *ptr);
FILE *xfdopen (int fd, char const *mode);
char *map_file_name (char const *filename);
/* Given an input file path, return a string that contains the path
with the file prefix mapping rules applied, or NULL if the input
was NULL. Do not free the return value. */
const char *map_file_name (char const *filename);
/* Add a new file prefix mapping. If a file path starts with
oldprefix, it will be replaced with newprefix. */