]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Don't hash .gch files twice; hash the hash instead
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 5 Sep 2010 19:43:06 +0000 (21:43 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 5 Sep 2010 19:43:06 +0000 (21:43 +0200)
ccache.c
ccache.h
hash.c

index 4fe730def4c81dbba3b97c253390006a8954b071..8c9045b6d8a6e17a324dc01a03dad8cfa8d24803 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -284,12 +284,12 @@ get_path_in_cache(const char *name, const char *suffix)
 static void
 remember_include_file(char *path, size_t path_len, struct mdfour *cpp_hash)
 {
-       struct file_hash *h;
        struct mdfour fhash;
        struct stat st;
        char *source = NULL;
        size_t size;
        int result;
+       bool is_pch;
 
        if (path_len >= 2 && (path[0] == '<' && path[path_len - 1] == '>')) {
                /* Typically <built-in> or <command-line>. */
@@ -324,12 +324,21 @@ remember_include_file(char *path, size_t path_len, struct mdfour *cpp_hash)
 
        hash_start(&fhash);
 
-       if (is_precompiled_header(path)) {
-               hash_file2(&fhash, cpp_hash, path);
+       is_pch = is_precompiled_header(path);
+       if (is_pch) {
+               struct file_hash pch_hash;
+               if (!hash_file(&fhash, path)) {
+                       goto failure;
+               }
+               hash_result_as_bytes(&fhash, pch_hash.hash);
+               pch_hash.size = fhash.totalN;
+               hash_delimiter(cpp_hash, "pch_hash");
+               hash_buffer(cpp_hash, pch_hash.hash, sizeof(pch_hash.hash));
        }
-
        if (enable_direct) {
-               if (!is_precompiled_header(path)) {
+               struct file_hash *h;
+
+               if (!is_pch) { /* else: the file has already been hashed. */
                        if (st.st_size > 0) {
                                if (!read_file(path, st.st_size, &source, &size)) {
                                        goto failure;
index 9977f60d1734f9652c1128aee9006cb1e8675626..eb6b282eb4d62bd25b265996799d4999ddf934a0 100644 (file)
--- a/ccache.h
+++ b/ccache.h
@@ -92,9 +92,7 @@ void hash_delimiter(struct mdfour *md, const char* type);
 void hash_string(struct mdfour *md, const char *s);
 void hash_int(struct mdfour *md, int x);
 bool hash_fd(struct mdfour *md, int fd);
-bool hash_fd2(struct mdfour *md1, struct mdfour *md2, int fd);
 bool hash_file(struct mdfour *md, const char *fname);
-bool hash_file2(struct mdfour *md1, struct mdfour *md2, const char *fname);
 
 /* ------------------------------------------------------------------------- */
 /* util.c */
diff --git a/hash.c b/hash.c
index 42e0935f13c388787acae7c6d768959bed885f4d..bcc012ac926f31e77225bd626735c52025598821 100644 (file)
--- a/hash.c
+++ b/hash.c
@@ -95,27 +95,12 @@ hash_int(struct mdfour *md, int x)
  */
 bool
 hash_fd(struct mdfour *md, int fd)
-{
-       return hash_fd2(md, NULL, fd);
-}
-
-/*
- * Add contents of an open file to the hash. Returns true on success, otherwise
- * false.
- */
-bool
-hash_fd2(struct mdfour *md1, struct mdfour *md2, int fd)
 {
        char buf[16384];
        ssize_t n;
 
        while ((n = read(fd, buf, sizeof(buf))) > 0) {
-               if (md1) {
-                       hash_buffer(md1, buf, n);
-               }
-               if (md2) {
-                       hash_buffer(md2, buf, n);
-               }
+               hash_buffer(md, buf, n);
        }
        return n == 0;
 }
@@ -126,16 +111,6 @@ hash_fd2(struct mdfour *md1, struct mdfour *md2, int fd)
  */
 bool
 hash_file(struct mdfour *md, const char *fname)
-{
-       return hash_file2(md, NULL, fname);
-}
-
-/*
- * Add contents of a file to two hash sums. Returns true on success, otherwise
- * false.
- */
-bool
-hash_file2(struct mdfour *md1, struct mdfour *md2, const char *fname)
 {
        int fd;
        bool ret;
@@ -145,7 +120,7 @@ hash_file2(struct mdfour *md1, struct mdfour *md2, const char *fname)
                return false;
        }
 
-       ret = hash_fd2(md1, md2, fd);
+       ret = hash_fd(md, fd);
        close(fd);
        return ret;
 }