From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 27AA01FAF1 for ; Wed, 16 Nov 2022 09:26:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1668590807; bh=4OR1qC3PK5YMScekRmcgjbDf6yc1Z8zfL/rerGMiHgI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=IgG6UHF55U0EdQ96m2IrSEd3iRLO/gd/fCwETwoYVD8h2XjfVitmKtvVcJGknHoVt Lpw39c3i25MwIlMXvIRZqfcgY9H6fnjBwh0dfzfgwUS1KUdRAQhl2hVXJj0FGLdXus cNhuDfiqcdg+UC0S1f7gDF7RtFR8C8Z41JzR4XOo= From: Eric Wong To: mwrap-perl@80x24.org Subject: [PATCH 3/6] wrap jhash calls to hash_loc Date: Wed, 16 Nov 2022 09:26:43 +0000 Message-Id: <20221116092646.19919-4-e@80x24.org> In-Reply-To: <20221116092646.19919-1-e@80x24.org> References: <20221116092646.19919-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This will make it easier to keep a consistent hash seed and/or switch to different hashes in the future. --- Mwrap.xs | 4 ++-- mwrap_core.h | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Mwrap.xs b/Mwrap.xs index 8aeb425..a5ffeed 100644 --- a/Mwrap.xs +++ b/Mwrap.xs @@ -164,12 +164,12 @@ CODE: k = (void *)kbuf; memcpy(k->k, &p, sizeof(p)); k->capa = 0; - k->hval = jhash(k->k, sizeof(p), 0xdeadbeef); + hash_loc(k, sizeof(p)); } else { k = (void *)kbuf; memcpy(k->k, str, len + 1); k->capa = len + 1; - k->hval = jhash(k->k, k->capa, 0xdeadbeef); + hash_loc(k, k->capa); } if (!k) diff --git a/mwrap_core.h b/mwrap_core.h index 94a6af3..d9396e6 100644 --- a/mwrap_core.h +++ b/mwrap_core.h @@ -272,6 +272,11 @@ static const COP *mwp_curcop(void) return NULL; } +static void hash_loc(struct src_loc *k, size_t len) +{ + k->hval = jhash(k->k, len, 0xdeadbeef); +} + static struct src_loc *assign_line(size_t size, const char *file, unsigned line) { /* avoid vsnprintf or anything which could call malloc here: */ @@ -298,7 +303,7 @@ static struct src_loc *assign_line(size_t size, const char *file, unsigned line) assert(dst && "bad math"); *dst = 0; /* terminate string */ k->capa = (uint32_t)(dst - k->k + 1); - k->hval = jhash(k->k, k->capa, 0xdeadbeef); + hash_loc(k, k->capa); return totals_add_rcu(k); } @@ -325,7 +330,7 @@ update_stats_rcu_lock(size_t *generation, size_t size, uintptr_t caller) k->total = size; memcpy(k->k, &caller, xlen); k->capa = 0; - k->hval = jhash(k->k, xlen, 0xdeadbeef); + hash_loc(k, xlen); ret = totals_add_rcu(k); } out: