the same string literal codegens to the same constant

this makes it so that you can send the same string literal
as a comptime slice and get the same type
This commit is contained in:
Andrew Kelley
2018-01-11 20:58:28 -05:00
parent 465e75bc5a
commit 3268276b58
6 changed files with 31 additions and 5 deletions

View File

@@ -67,9 +67,12 @@ bool buf_eql_buf(Buf *buf, Buf *other) {
uint32_t buf_hash(Buf *buf) {
assert(buf->list.length);
size_t interval = buf->list.length / 256;
if (interval == 0)
interval = 1;
// FNV 32-bit hash
uint32_t h = 2166136261;
for (size_t i = 0; i < buf_len(buf); i += 1) {
for (size_t i = 0; i < buf_len(buf); i += interval) {
h = h ^ ((uint8_t)buf->list.at(i));
h = h * 16777619;
}