Update on calc_file_hash. Use xor instead of +. Only calculate has if file name differs in search_cached_include.
Unified · Split
| @@ -1622,12 +1622,10 @@ static unsigned long long calc_file_hash(const char *filename) · 1621 unmodified lines | |||
| 1622 | if (n <= 0) | 1622 | if (n <= 0) |
| 1623 | break; | 1623 | break; |
| 1624 | for (i = 0; i < n; i++) | 1624 | for (i = 0; i < n; i++) |
| 1625 | hash = hash * 1099511628211ull + temp[i]; // FNV_prime | 1625 | hash = hash * 1099511628211ull ^ temp[i]; // FNV_prime |
| 1626 | } | 1626 | } |
| 1627 | fclose(fp); | 1627 | fclose(fp); |
| 1628 | if (hash == 0) | 1628 | return hash ? hash : 1ull; |
| 1629 | hash = 1; | ||
| 1630 | return hash; | ||
| 1631 | } | 1629 | } |
| 1632 | #endif | 1630 | #endif |
| 1633 | 1631 | ||
| @@ -1658,10 +1656,14 @@ static CachedInclude *search_cached_include(TCCState *s1, const char *filename, · 24 unmodified lines | |||
| 1658 | break; | 1656 | break; |
| 1659 | e = s1->cached_includes[i - 1]; | 1657 | e = s1->cached_includes[i - 1]; |
| 1660 | if (e->st.st_size == st.st_size) { | 1658 | if (e->st.st_size == st.st_size) { |
| 1659 | if (0 == PATHCMP(e->filename, filename)) { | ||
| 1660 | hash = e->hash; | ||
| 1661 | break; | ||
| 1662 | } | ||
| 1661 | if (e->hash == 0) | 1663 | if (e->hash == 0) |
| 1662 | e->hash = calc_file_hash(e->filename); | 1664 | e->hash = calc_file_hash(e->filename); |
| 1663 | hash = calc_file_hash(filename); | 1665 | if (hash == 0) |
| 1664 | break; | 1666 | hash = calc_file_hash(filename); |
| 1665 | } | 1667 | } |
| 1666 | i = e->hash_next; | 1668 | i = e->hash_next; |
| 1667 | } | 1669 | } |