From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id CFD313850235 for ; Fri, 26 Aug 2022 20:23:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CFD313850235 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B2F2023A; Fri, 26 Aug 2022 13:23:41 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E7F4A3F67D; Fri, 26 Aug 2022 13:23:35 -0700 (PDT) From: Richard Sandiford To: Richard Biener Mail-Followup-To: Richard Biener ,Martin Jambor , GCC Patches , richard.sandiford@arm.com Cc: Martin Jambor , GCC Patches Subject: Re: [PATCH 2/2] vec: Add array_slice::bsearch References: <97EB95B8-B901-4290-AA80-3116209F9EBC@suse.de> Date: Fri, 26 Aug 2022 21:23:34 +0100 In-Reply-To: <97EB95B8-B901-4290-AA80-3116209F9EBC@suse.de> (Richard Biener's message of "Fri, 26 Aug 2022 20:24:07 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-44.2 required=5.0 tests=BAYES_00,KAM_DMARC_NONE,KAM_DMARC_STATUS,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Richard Biener writes: >> Am 26.08.2022 um 18:40 schrieb Martin Jambor : >>=20 >> =EF=BB=BFHi, >>=20 >> This adds a method to binary search in a sorted array_slice. >>=20 >> The implementation is direct copy of vec:bsearch. Moreover, to only >> copy it once and not twice, I used const_cast in the non-const >> variants to be able to use the const variants. I hope that is >> acceptable abuse of const_cast but I'll be happy to change that if >> not. >>=20 >> Bootstrapped and tested along code that actually uses it on >> x86_64-linux. OK for trunk? > > Can you avoid the copying by using array slice bsearch from the vec<> bse= arch? IMO it would be better to transition to using routines for this kind of thing (for new code). In this case that would be std::lower_bound. Using std::lower_bound is more convenient because it avoids the void * thing (you can use lambdas to capture any number of variables instead) and because it works on subranges, not just whole ranges. Thanks, Richard