From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 2A2D03864A3F for ; Tue, 6 Dec 2022 13:57:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2A2D03864A3F Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com X-ASG-Debug-ID: 1670335053-0c856e762b1bb30001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id AMoEWahDg77g7HSc (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 0C196441D64; Tue, 6 Dec 2022 08:57:33 -0500 (EST) From: Simon Marchi 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 09/12] gdbsupport: add gdb::string_view_hash Date: Tue, 6 Dec 2022 08:57:26 -0500 X-ASG-Orig-Subj: [PATCH 09/12] gdbsupport: add gdb::string_view_hash Message-Id: <20221206135729.3937767-10-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 Content-Transfer-Encoding: 8bit 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: 1590 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 List-Id: Add the string_view_hash type, which will be useful to be able to use gdb::string_view as std::unordered_map keys. Use it in gdb/symtab.c, to exercise it. Change-Id: Id69a466ab19a9f6620b5df8a2dd29b5cddd94c00 --- gdb/symtab.c | 2 +- gdbsupport/common-utils.h | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index 0d342f765f2..f6ddd8e3c41 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -812,7 +812,7 @@ hash_demangled_name_entry (const void *data) const struct demangled_name_entry *e = (const struct demangled_name_entry *) data; - return fast_hash (e->mangled.data (), e->mangled.length ()); + return gdb::string_view_hash () (e->mangled); } /* Equality function for the demangled name hash. */ diff --git a/gdbsupport/common-utils.h b/gdbsupport/common-utils.h index fae77640666..2525d287c87 100644 --- a/gdbsupport/common-utils.h +++ b/gdbsupport/common-utils.h @@ -193,4 +193,21 @@ fast_hash (const void *ptr, size_t len, unsigned int start_value = 0) #endif } +namespace gdb +{ + +/* Hash type for gdb::string_view. + + Even after we switch to C++17 and dump our string_view implementation, we + might want to keep this hash implementation if it's faster than std::hash + for std::string_view. */ + +struct string_view_hash +{ + std::size_t operator() (gdb::string_view view) const + { return fast_hash (view.data (), view.length ()); } +}; + +} /* namespace gdb */ + #endif /* COMMON_COMMON_UTILS_H */ -- 2.38.1