From patchwork Tue Dec 6 13:57:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 61558 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EE99F3848E3C for ; Tue, 6 Dec 2022 14:00:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE99F3848E3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670335205; bh=HD9Gks682L+7fwmyV1JmnJMro6WJIYPvmOXawtu1wrw=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=GYYBm9q67xCBecJQLwpUz8FEN6OdnhM+0Rse5ZEd1QwTXuDUa6ADbFeVRTh8c/omy nwlT4bD8pvHTctI2GmkW2ABBlcnIaxLO+43TMZCCuvC81W2IflOdBQ4CvSmB5lyURr 5Xki0CiBcU+NVQEnGnmRHuMLGKr06wrgay6eh+aI= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 2A2AC3864A3C for ; Tue, 6 Dec 2022 13:57:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2A2AC3864A3C X-ASG-Debug-ID: 1670335052-0c856e762a1bb00001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id pDLI5TdZYobDkJA8 (version=TLSv1 cipher=AES128-SHA bits=128 verify=NO); Tue, 06 Dec 2022 08:57:33 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@efficios.com X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from epycamd.internal.efficios.com (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by smtp.ebox.ca (Postfix) with ESMTP id E7551441B21; Tue, 6 Dec 2022 08:57:32 -0500 (EST) X-Barracuda-RBL-IP: 192.222.180.24 X-Barracuda-Effective-Source-IP: 192-222-180-24.qc.cable.ebox.net[192.222.180.24] X-Barracuda-Apparent-Source-IP: 192.222.180.24 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 08/12] gdbsupport: move fast_hash to gdbsupport/common-utils.h Date: Tue, 6 Dec 2022 08:57:25 -0500 X-ASG-Orig-Subj: [PATCH 08/12] gdbsupport: move fast_hash to gdbsupport/common-utils.h Message-Id: <20221206135729.3937767-9-simon.marchi@efficios.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221206135729.3937767-1-simon.marchi@efficios.com> References: <20221206135729.3937767-1-simon.marchi@efficios.com> MIME-Version: 1.0 X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1670335053 X-Barracuda-Encrypted: AES128-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 2641 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=5.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.102644 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Spam-Status: No, score=-3498.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Simon Marchi via Gdb-patches From: Simon Marchi Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" The following patch adds a hash type for gdb::string_view in gdbsupport, which will use the fast_hash function. Move the latter to gdbsupport. Change-Id: Id74510e17801e775bd5ffa5f443713d79adf14ad --- gdb/utils.h | 19 ------------------- gdbsupport/common-utils.h | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/gdb/utils.h b/gdb/utils.h index d2acf899ba2..65080a9b9ce 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -26,10 +26,6 @@ #include "gdbsupport/scoped_restore.h" #include -#ifdef HAVE_LIBXXHASH -#include -#endif - struct completion_match_for_lcd; class compiled_regex; @@ -365,19 +361,4 @@ extern void copy_bitwise (gdb_byte *dest, ULONGEST dest_offset, const gdb_byte *source, ULONGEST source_offset, ULONGEST nbits, int bits_big_endian); -/* A fast hashing function. This can be used to hash data in a fast way - when the length is known. If no fast hashing library is available, falls - back to iterative_hash from libiberty. START_VALUE can be set to - continue hashing from a previous value. */ - -static inline unsigned int -fast_hash (const void *ptr, size_t len, unsigned int start_value = 0) -{ -#ifdef HAVE_LIBXXHASH - return XXH64 (ptr, len, start_value); -#else - return iterative_hash (ptr, len, start_value); -#endif -} - #endif /* UTILS_H */ diff --git a/gdbsupport/common-utils.h b/gdbsupport/common-utils.h index 8a9448a638b..fae77640666 100644 --- a/gdbsupport/common-utils.h +++ b/gdbsupport/common-utils.h @@ -27,6 +27,12 @@ #include "poison.h" #include "gdb_string_view.h" +#if defined HAVE_LIBXXHASH +# include +#else +# include "hashtab.h" +#endif + /* xmalloc(), xrealloc() and xcalloc() have already been declared in "libiberty.h". */ @@ -172,4 +178,19 @@ extern int hex2bin (const char *hex, gdb_byte *bin, int count); /* Like the above, but return a gdb::byte_vector. */ gdb::byte_vector hex2bin (const char *hex); +/* A fast hashing function. This can be used to hash data in a fast way + when the length is known. If no fast hashing library is available, falls + back to iterative_hash from libiberty. START_VALUE can be set to + continue hashing from a previous value. */ + +static inline unsigned int +fast_hash (const void *ptr, size_t len, unsigned int start_value = 0) +{ +#if defined HAVE_LIBXXHASH + return XXH64 (ptr, len, start_value); +#else + return iterative_hash (ptr, len, start_value); +#endif +} + #endif /* COMMON_COMMON_UTILS_H */