Small update on pragma once

Update on calc_file_hash. Use xor instead of +.
Only calculate has if file name differs in search_cached_include.
This commit is contained in:
herman ten brugge 2023-06-26 06:33:46 +02:00
parent 30fd24abd4
commit 4e363a1728

14
tccpp.c
View File

@ -1622,12 +1622,10 @@ static unsigned long long calc_file_hash(const char *filename)
if (n <= 0) if (n <= 0)
break; break;
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
hash = hash * 1099511628211ull + temp[i]; // FNV_prime hash = hash * 1099511628211ull ^ temp[i]; // FNV_prime
} }
fclose(fp); fclose(fp);
if (hash == 0) return hash ? hash : 1ull;
hash = 1;
return hash;
} }
#endif #endif
@ -1658,10 +1656,14 @@ static CachedInclude *search_cached_include(TCCState *s1, const char *filename,
break; break;
e = s1->cached_includes[i - 1]; e = s1->cached_includes[i - 1];
if (e->st.st_size == st.st_size) { if (e->st.st_size == st.st_size) {
if (0 == PATHCMP(e->filename, filename)) {
hash = e->hash;
break;
}
if (e->hash == 0) if (e->hash == 0)
e->hash = calc_file_hash(e->filename); e->hash = calc_file_hash(e->filename);
hash = calc_file_hash(filename); if (hash == 0)
break; hash = calc_file_hash(filename);
} }
i = e->hash_next; i = e->hash_next;
} }