From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 6322F3858D28 for ; Fri, 5 Nov 2021 20:01:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6322F3858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca Received: from [172.16.0.95] (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 066D41E813; Fri, 5 Nov 2021 16:01:22 -0400 (EDT) Subject: Re: [PATCH v2 08/32] Add new overload of dwarf5_djb_hash To: Tom Tromey , gdb-patches@sourceware.org References: <20211104180907.2360627-1-tom@tromey.com> <20211104180907.2360627-9-tom@tromey.com> From: Simon Marchi Message-ID: Date: Fri, 5 Nov 2021 16:01:21 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20211104180907.2360627-9-tom@tromey.com> Content-Type: text/plain; charset=utf-8 Content-Language: tl Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Fri, 05 Nov 2021 20:01:23 -0000 On 2021-11-04 2:08 p.m., Tom Tromey wrote: > This adds a new overload of dwarf5_djb_hash. This is used in > subsequent patches. > --- > gdb/dwarf2/index-common.c | 15 +++++++++++++++ > gdb/dwarf2/index-common.h | 4 ++++ > 2 files changed, 19 insertions(+) > > diff --git a/gdb/dwarf2/index-common.c b/gdb/dwarf2/index-common.c > index 1c02730a3fe..4bad82218c2 100644 > --- a/gdb/dwarf2/index-common.c > +++ b/gdb/dwarf2/index-common.c > @@ -54,3 +54,18 @@ dwarf5_djb_hash (const char *str_) > hash = hash * 33 + tolower (c); > return hash; > } > + > +/* See dwarf-index-common.h. */ > + > +uint32_t > +dwarf5_djb_hash (gdb::string_view str) > +{ > + /* Note: tolower here ignores UTF-8, which isn't fully compliant. > + See http://dwarfstd.org/ShowIssue.php?issue=161027.1. */ > + > + uint32_t hash = 5381; > + size_t len = str.length (); > + for (size_t i = 0; i < len; ++i) > + hash = hash * 33 + tolower (str[i] & 0xff); > + return hash; > +} For bonus points, you could iterate using: for (char c : str) ... unless you see a good reason not to. Simon