From c58d707f49c42586d345bdfc22e8549ac4185504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Thu, 15 Sep 2022 00:25:31 +0000 Subject: [PATCH] better implementation of event.hash() --- ui/src/components/calendar/event.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ui/src/components/calendar/event.ts b/ui/src/components/calendar/event.ts index d26f37b..be016cf 100644 --- a/ui/src/components/calendar/event.ts +++ b/ui/src/components/calendar/event.ts @@ -18,13 +18,11 @@ export default class Event { public get hash(): string { const str = JSON.stringify(this); - // from https://gist.github.com/jlevy/c246006675becc446360a798e2b2d781 + // source: https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0?permalink_comment_id=2775538#gistcomment-2775538 let hash = 0; - for (let i = 0; i < str.length; i++) { - const char = str.charCodeAt(i); - hash = (hash << 5) - hash + char; - hash &= hash; // Convert to 32bit integer - } + for (let i = 0; i < str.length; i++) + hash = Math.imul(31, hash) + str.charCodeAt(i) | 0; + return new Uint32Array([hash])[0].toString(36); } } \ No newline at end of file