Cleanup hash implementation

This commit is contained in:
gingerBill
2021-09-23 12:41:48 +01:00
parent a7f59ab388
commit 6a86b3c82b
+4 -4
View File
@@ -398,9 +398,9 @@ get_id_uintptr :: #force_inline proc(ctx: ^Context, ptr: uintptr) -> Id {
get_id_bytes :: proc(ctx: ^Context, bytes: []byte) -> Id { get_id_bytes :: proc(ctx: ^Context, bytes: []byte) -> Id {
/* 32bit fnv-1a hash */ /* 32bit fnv-1a hash */
HASH_INITIAL :: 2166136261 HASH_INITIAL :: 2166136261
hash :: proc(hash: ^Id, data: rawptr, size: int) { hash :: proc(hash: ^Id, data: []byte) {
size := size size := len(data)
cptr := ([^]u8)(data) cptr := ([^]u8)(raw_data(data))
for ; size > 0; size -= 1 { for ; size > 0; size -= 1 {
hash^ = Id(u32(hash^) ~ u32(cptr[0])) * 16777619 hash^ = Id(u32(hash^) ~ u32(cptr[0])) * 16777619
cptr = cptr[1:] cptr = cptr[1:]
@@ -409,7 +409,7 @@ get_id_bytes :: proc(ctx: ^Context, bytes: []byte) -> Id {
idx := ctx.id_stack.idx idx := ctx.id_stack.idx
res := ctx.id_stack.items[idx - 1] if idx > 0 else HASH_INITIAL res := ctx.id_stack.items[idx - 1] if idx > 0 else HASH_INITIAL
hash(&res, &bytes[0], len(bytes)) hash(&res, bytes)
ctx.last_id = res ctx.last_id = res
return res return res
} }