From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23292 invoked by alias); 23 Oct 2019 16:37:48 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 23284 invoked by uid 89); 23 Oct 2019 16:37:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=H*Ad:D*rs, 47PM, 47pm X-HELO: gate.crashing.org Received: from gate.crashing.org (HELO gate.crashing.org) (63.228.1.57) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 23 Oct 2019 16:37:46 +0000 Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id x9NGbROI027512; Wed, 23 Oct 2019 11:37:28 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id x9NGbQmY027511; Wed, 23 Oct 2019 11:37:26 -0500 Date: Wed, 23 Oct 2019 16:41:00 -0000 From: Segher Boessenkool To: Alexander Monakov Cc: Eduard-Mihai Burtescu , Ian Lance Taylor , gcc-patches , Ian Lance Taylor Subject: Re: [PATCH] Refactor rust-demangle to be independent of C++ demangling. Message-ID: <20191023163726.GO28442@gate.crashing.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-IsSubscribed: yes X-SW-Source: 2019-10/txt/msg01676.txt.bz2 On Wed, Oct 23, 2019 at 07:22:47PM +0300, Alexander Monakov wrote: > On Wed, 23 Oct 2019, Eduard-Mihai Burtescu wrote: > > @@ -384,6 +384,14 @@ rust_demangle_callback (const char *mangled, int options, > > return 0; > > rdm.sym_len--; > > > > + /* Legacy Rust symbols also always end with a path segment > > + that encodes a 16 hex digit hash, i.e. '17h[a-f0-9]{16}'. > > + This early check, before any parse_ident calls, should > > + quickly filter out most C++ symbols unrelated to Rust. */ > > + if (!(rdm.sym_len > 19 > > + && !strncmp (&rdm.sym[rdm.sym_len - 19], "17h", 3))) > > This can be further optimized by using memcmp in place of strncmp, since from > the length check you know that you won't see the null terminator among the three > chars you're checking. > > The compiler can expand memcmp(buf, "abc", 3) inline as two comparisons against > a 16-bit immediate and an 8-bit immediate. It can't do the same for strncmp. The compiler does not currently do that, but it *could*. Or why not? The compiler is always allowed to load 3 characters here, whether some string has a NUL character earlier or not. Segher