From 9a785e0f063926ddf2a479a618dd2ae16cf2d5b1 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Thu, 21 Nov 2024 00:50:11 +0100 Subject: [PATCH] use builtin hash functions instead of rolling my own --- src/ugui_button.c3 | 2 +- src/ugui_data.c3 | 16 ---------------- src/ugui_div.c3 | 2 +- src/ugui_impl.c3 | 2 +- src/ugui_slider.c3 | 4 ++-- 5 files changed, 5 insertions(+), 21 deletions(-) diff --git a/src/ugui_button.c3 b/src/ugui_button.c3 index 8d7aac4..ac90857 100644 --- a/src/ugui_button.c3 +++ b/src/ugui_button.c3 @@ -5,7 +5,7 @@ import std::io; // draw a button, return the events on that button fn ElemEvents! Ctx.button(&ctx, String label, Rect size) { - Id id = hash(label); + Id id = label.hash(); Elem *parent = ctx.get_parent()!; Elem *c_elem = ctx.get_elem(id)!; diff --git a/src/ugui_data.c3 b/src/ugui_data.c3 index 3e043c5..945de02 100644 --- a/src/ugui_data.c3 +++ b/src/ugui_data.c3 @@ -104,22 +104,6 @@ fault UgError { UNEXPECTED_ELEMENT, } -fn Id fnv1a(String str) -{ - const ulong FNV_OFF = 0xcbf29ce484222325; - const ulong FNV_PRIME = 0x100000001b3; - - ulong hash = FNV_OFF; - foreach (c : str) { - hash ^= c; - hash *= FNV_PRIME; - } - - return hash; -} - -macro hash(String str) { return fnv1a(str); } - macro uint_to_rgba(uint u) { return Color{ .r = (char)((u >> 24) & 0xff), diff --git a/src/ugui_div.c3 b/src/ugui_div.c3 index 45d8387..e17b278 100644 --- a/src/ugui_div.c3 +++ b/src/ugui_div.c3 @@ -4,7 +4,7 @@ import std::io; fn void! Ctx.div_begin(&ctx, String label, Rect size) { - Id id = hash(label); + Id id = label.hash(); Elem *parent = ctx.get_parent()!; Elem* c_elem = ctx.get_elem(id)!; diff --git a/src/ugui_impl.c3 b/src/ugui_impl.c3 index 17a2b04..89fb177 100644 --- a/src/ugui_impl.c3 +++ b/src/ugui_impl.c3 @@ -28,7 +28,7 @@ macro Ctx.get_elem(&ctx, Id id) // if it does't find one macro Ctx.get_elem_by_label(&ctx, String label) { - Id id = hash(label); + Id id = label.hash(); return ctx.cache.search(id); } diff --git a/src/ugui_slider.c3 b/src/ugui_slider.c3 index a32524a..6eae35b 100644 --- a/src/ugui_slider.c3 +++ b/src/ugui_slider.c3 @@ -9,7 +9,7 @@ import std::io; */ fn ElemEvents! Ctx.slider_hor(&ctx, String label, Rect size) { - Id id = hash(label); + Id id = label.hash(); Elem *parent = ctx.get_parent()!; Elem *c_elem = ctx.get_elem(id)!; @@ -81,7 +81,7 @@ fn ElemEvents! Ctx.slider_hor(&ctx, String label, Rect size) */ fn ElemEvents! Ctx.slider_ver(&ctx, String label, Rect size) { - Id id = hash(label); + Id id = label.hash(); Elem *parent = ctx.get_parent()!; Elem *c_elem = ctx.get_elem(id)!;