aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Johansson <erik@ejohansson.se>2020-03-01 21:17:49 +0100
committerGitHub <noreply@github.com>2020-03-01 21:17:49 +0100
commitdf961358240487afdc4a92eb4bc7db25e6f931de (patch)
treefcdfdcf9caac8b70e9d56565fc807851462d8343
parente0f5063b159de97ca9cc3dae8dbab67628ccb33d (diff)
downloadccache-df961358240487afdc4a92eb4bc7db25e6f931de.tar.gz
ccache-df961358240487afdc4a92eb4bc7db25e6f931de.tar.bz2
ccache-df961358240487afdc4a92eb4bc7db25e6f931de.zip
Avoid duplicate stat calls (#550)
hash_source_code_string will, in read_file, stat the file to get the file size. But when called from verify_result, the file size is already known so by using this size the number of stat calls in a normal run can be cut in half.
-rw-r--r--src/hashutil.cpp7
-rw-r--r--src/hashutil.hpp3
-rw-r--r--src/manifest.cpp2
3 files changed, 8 insertions, 4 deletions
diff --git a/src/hashutil.cpp b/src/hashutil.cpp
index f8ac4853..81f545c6 100644
--- a/src/hashutil.cpp
+++ b/src/hashutil.cpp
@@ -264,7 +264,10 @@ hash_source_code_string(const Config& config,
// Hash a file ignoring comments. Returns a bitmask of HASH_SOURCE_CODE_*
// results.
int
-hash_source_code_file(const Config& config, struct hash* hash, const char* path)
+hash_source_code_file(const Config& config,
+ struct hash* hash,
+ const char* path,
+ size_t size_hint)
{
if (is_precompiled_header(path)) {
if (hash_file(hash, path)) {
@@ -275,7 +278,7 @@ hash_source_code_file(const Config& config, struct hash* hash, const char* path)
} else {
char* data;
size_t size;
- if (!read_file(path, 0, &data, &size)) {
+ if (!read_file(path, size_hint, &data, &size)) {
return HASH_SOURCE_CODE_ERROR;
}
int result = hash_source_code_string(config, hash, data, size, path);
diff --git a/src/hashutil.hpp b/src/hashutil.hpp
index a6299186..0f3cfc74 100644
--- a/src/hashutil.hpp
+++ b/src/hashutil.hpp
@@ -43,7 +43,8 @@ int hash_source_code_string(const Config& config,
const char* path);
int hash_source_code_file(const Config& config,
struct hash* hash,
- const char* path);
+ const char* path,
+ size_t size_hint = 0);
bool hash_command_output(struct hash* hash,
const char* command,
const char* compiler);
diff --git a/src/manifest.cpp b/src/manifest.cpp
index 961c6268..67410ffe 100644
--- a/src/manifest.cpp
+++ b/src/manifest.cpp
@@ -447,7 +447,7 @@ verify_result(const Context& ctx,
auto hashed_files_iter = hashed_files.find(path);
if (hashed_files_iter == hashed_files.end()) {
struct hash* hash = hash_init();
- int ret = hash_source_code_file(ctx.config, hash, path.c_str());
+ int ret = hash_source_code_file(ctx.config, hash, path.c_str(), fs.size);
if (ret & HASH_SOURCE_CODE_ERROR) {
cc_log("Failed hashing %s", path.c_str());
hash_free(hash);