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 | 1622 | if (n <= 0) |
| 1623 | 1623 | break; |
| 1624 | 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 | 1627 | fclose(fp); |
| 1628 | − if (hash == 0) | |
| 1629 | − hash = 1; | |
| 1630 | − return hash; | |
| 1628 | + return hash ? hash : 1ull; | |
| 1631 | 1629 | } |
| 1632 | 1630 | #endif |
| 1633 | 1631 | |
| @@ -1658,10 +1656,14 @@ static CachedInclude *search_cached_include(TCCState *s1, const char *filename, · 24 unmodified lines | ||
| 1658 | 1656 | break; |
| 1659 | 1657 | e = s1->cached_includes[i - 1]; |
| 1660 | 1658 | if (e->st.st_size == st.st_size) { |
| 1659 | + if (0 == PATHCMP(e->filename, filename)) { | |
| 1660 | + hash = e->hash; | |
| 1661 | + break; | |
| 1662 | + } | |
| 1661 | 1663 | if (e->hash == 0) |
| 1662 | 1664 | e->hash = calc_file_hash(e->filename); |
| 1663 | − hash = calc_file_hash(filename); | |
| 1664 | − break; | |
| 1665 | + if (hash == 0) | |
| 1666 | + hash = calc_file_hash(filename); | |
| 1665 | 1667 | } |
| 1666 | 1668 | i = e->hash_next; |
| 1667 | 1669 | } |