]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
use mmap() to solve the problem of incredibly long pre-processor lines
authorAndrew Tridgell <tridge@samba.org>
Wed, 27 Mar 2002 07:06:45 +0000 (08:06 +0100)
committerAndrew Tridgell <tridge@samba.org>
Wed, 27 Mar 2002 07:06:45 +0000 (08:06 +0100)
Makefile
ccache.c
ccache.h
hash.c

index 565d5dbe7cc1b072974fd4c99b0fa450161ead8c..592f578fe606032c1a2a5156f9b94b970ead9b01 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-CFLAGS=-W -Wall -
+CFLAGS=-W -Wall -O2
 CC=gcc
 
 OBJS= ccache.o mdfour.o hash.o execute.o util.o args.o
index 27e2a4061e7999ef746c42ecaeeb7d826133e36d..17c620260c83462f13cd71b6076eacfcc79f73af 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -107,39 +107,41 @@ static void to_cache(ARGS *args)
 */
 static void stabs_hash(const char *fname)
 {
-       FILE *f;
-       char *s;
-       static char *line;
-
-       if (!line) line = malloc(MAX_LINE_SIZE);
-       if (!line) {
-               cc_log("Can't allocate in stabs hash!\n");
+       int fd;
+       struct stat st; 
+       char *map;
+       int l_start, l_end;
+
+       fd = open(fname, O_RDONLY);
+       if (fd == -1 || fstat(fd, &st) != 0) {
+               cc_log("Failed to open preprocessor output %s\n", fname);
                failed();
        }
 
-       line[MAX_LINE_SIZE-2] = 0;
-
-       f = fopen(fname, "r");
-       if (!f) {
-               cc_log("Failed to open preprocessor output\n");
+       map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+       if (map == (void *)-1) {
+               cc_log("Failed to mmap %s\n", fname);
                failed();
        }
-       
-       while ((s = fgets(line, MAX_LINE_SIZE, f))) {
-               if (line[MAX_LINE_SIZE-2]) {
-                       cc_log("line too long in preprocessor output!\n");
-                       failed();
-               }
+       close(fd);
 
-               /* ignore debugging output */
-               if (line[0] == '#' && line[1] == ' ' && isdigit(line[2])) {
+       l_start = 0;
+       while (l_start < st.st_size) {
+               l_end = l_start;
+               while (l_end < st.st_size && map[l_end] != '\n') {
+                       l_end++;
+               }
+               if ((l_end - l_start) > 2 &&
+                   map[l_start] == '#' && map[l_start+1] == ' ' && 
+                   isdigit(map[l_start+2])) {
+                       l_start = l_end+1;
                        continue;
                }
-
-               hash_string(s);
+               hash_buffer(&map[l_start], 1 + l_end - l_start);
+               l_start = l_end+1;
        }
 
-       fclose(f);
+       munmap(map, st.st_size);
 }
 
 
index 99ea571701faafc5764b47b05f09df5c5e7bc963..cf2b1bb095542c64f2a2584f3663c25f7c7402e2 100644 (file)
--- a/ccache.h
+++ b/ccache.h
@@ -8,6 +8,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <sys/mman.h>
 #include <fcntl.h>
 #include <string.h>
 #include <ctype.h>
@@ -29,6 +30,7 @@ void hash_string(const char *s);
 void hash_int(int x);
 void hash_file(const char *fname);
 char *hash_result(void);
+void hash_buffer(const char *s, int len);
 
 void cc_log(const char *format, ...);
 void fatal(const char *msg);
diff --git a/hash.c b/hash.c
index 8d49c2fbbf38ec388cbb459e62ad54d5aef2c578..e4ec119ff903546f7457100125b165d758013d96 100644 (file)
--- a/hash.c
+++ b/hash.c
@@ -33,6 +33,11 @@ void hash_string(const char *s)
        mdfour_update(&md, s, strlen(s));
 }
 
+void hash_buffer(const char *s, int len)
+{
+       mdfour_update(&md, s, len);
+}
+
 void hash_int(int x)
 {
        mdfour_update(&md, (unsigned char *)&x, sizeof(x));