From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1952 invoked by alias); 23 Oct 2019 16:22:52 -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 1944 invoked by uid 89); 23 Oct 2019 16:22:52 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-4.2 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.1 spammy=H*r:MSK, H*F:D*ru X-HELO: smtp.ispras.ru Received: from bran.ispras.ru (HELO smtp.ispras.ru) (83.149.199.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 23 Oct 2019 16:22:50 +0000 Received: from [10.10.3.121] (monopod.intra.ispras.ru [10.10.3.121]) by smtp.ispras.ru (Postfix) with ESMTP id C4914201D0; Wed, 23 Oct 2019 19:22:47 +0300 (MSK) Date: Wed, 23 Oct 2019 16:37:00 -0000 From: Alexander Monakov To: Eduard-Mihai Burtescu cc: Ian Lance Taylor , gcc-patches , Ian Lance Taylor Subject: Re: [PATCH] Refactor rust-demangle to be independent of C++ demangling. In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20.13 (LNX 116 2015-12-14) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-SW-Source: 2019-10/txt/msg01675.txt.bz2 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. Alexander