From: Joel Rosdahl Date: Sun, 5 Sep 2010 19:43:06 +0000 (+0200) Subject: Don't hash .gch files twice; hash the hash instead X-Git-Tag: v3.1~16 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a914a9746268c6108cce66094f070f6038492c98;p=thirdparty%2Fccache.git Don't hash .gch files twice; hash the hash instead --- diff --git a/ccache.c b/ccache.c index 4fe730def..8c9045b6d 100644 --- 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 or . */ @@ -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; diff --git a/ccache.h b/ccache.h index 9977f60d1..eb6b282eb 100644 --- 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 42e0935f1..bcc012ac9 100644 --- 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; }