From patchwork Tue Oct 22 16:47:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 35225 Received: (qmail 6783 invoked by alias); 22 Oct 2019 16:47:42 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 6764 invoked by uid 89); 22 Oct 2019 16:47:42 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 22 Oct 2019 16:47:41 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id AF7B8204A4; Tue, 22 Oct 2019 12:47:38 -0400 (EDT) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [IPv6:2620:52:3:1:5054:ff:fe06:16ca]) by mx1.osci.io (Postfix) with ESMTP id A5A7C2018B; Tue, 22 Oct 2019 12:47:35 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 833C023814; Tue, 22 Oct 2019 12:47:35 -0400 (EDT) X-Gerrit-PatchSet: 6 Date: Tue, 22 Oct 2019 12:47:34 -0400 From: "Christian Biesinger (Code Review)" To: Christian Biesinger , Tom Tromey , Simon Marchi , Sergio Durigan Junior , gdb-patches@sourceware.org Auto-Submitted: auto-generated X-Gerrit-MessageType: newpatchset Subject: [review v6] Add a fast_hash function in common-utils X-Gerrit-Change-Id: I77cac0d9aa78fc65316a2af449f52edcae72dc9b X-Gerrit-Change-Number: 38 X-Gerrit-ChangeURL: X-Gerrit-Commit: 1a6ff1a96b302283d517b3cdeae7310adecbe859 In-Reply-To: References: Reply-To: cbiesinger@google.com, simon.marchi@polymtl.ca, tromey@sourceware.org, sergiodj@redhat.com, cbiesinger@google.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3 Message-Id: <20191022164735.833C023814@gnutoolchain-gerrit.osci.io> Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/38 ...................................................................... Add a fast_hash function in common-utils Also updates a caller in symtab.c. For now this just calls htab_hash_string but the next patch will change it to xxhash, if available. gdb/ChangeLog: 2019-10-22 Christian Biesinger * utils.h (fast_hash): New function. * symtab.c (hash_demangled_name_entry): Call new function fast_hash. Change-Id: I77cac0d9aa78fc65316a2af449f52edcae72dc9b --- M gdb/ChangeLog M gdb/symtab.c M gdb/utils.h 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index d271330..bbf5d08 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2019-10-22 Christian Biesinger + * utils.h (fast_hash): New function. + * symtab.c (hash_demangled_name_entry): Call new function + fast_hash. + +2019-10-22 Christian Biesinger + * symtab.c (struct demangled_name_entry): Change type of mangled to gdb::string_view. Also adds a constructor that takes the mangled name. diff --git a/gdb/symtab.c b/gdb/symtab.c index 567d09d..dff92ca 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -70,6 +70,7 @@ #include #include "gdbsupport/gdb_string_view.h" #include "gdbsupport/pathstuff.h" +#include "gdbsupport/common-utils.h" /* Forward declarations for local functions. */ @@ -727,7 +728,7 @@ const struct demangled_name_entry *e = (const struct demangled_name_entry *) data; - return iterative_hash (e->mangled.data (), e->mangled.length (), 0); + return fast_hash (e->mangled.data (), e->mangled.length ()); } /* Equality function for the demangled name hash. */ diff --git a/gdb/utils.h b/gdb/utils.h index af8b461..478c485 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -567,4 +567,14 @@ const gdb_byte *source, ULONGEST source_offset, ULONGEST nbits, int bits_big_endian); +/* A fast hashing function. This can be used to hash strings in a fast way + when the length is known. If no fast hashing library is available, falls + back to iterative_hash from libiberty. */ + +static inline unsigned int +fast_hash (const char* str, size_t len) +{ + return iterative_hash (str, len, 0); +} + #endif /* UTILS_H */