From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 9DB80384D15B for ; Fri, 26 Aug 2022 21:45:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9DB80384D15B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 915D41F96B; Fri, 26 Aug 2022 21:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1661550316; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jv4hq/o7h78PALAD3/2j2/YGaPu22YNHL/3w/FLYt5s=; b=wLVRVbcDbv299t5pYPMzVfnH7CHAYhSkifrxrjlHOHR5/j1Y/Xgw/cH1GfhH6fPSN4Qq4s NMjBL1y/pxHNkgLzoueWHznXNaLHpm6JsSniJAQ/OBSebSkfc7ssze9SKxKxxplWh9vK/U N6UsF6Au3KoioGXchijTHlLrLwfOus4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1661550316; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jv4hq/o7h78PALAD3/2j2/YGaPu22YNHL/3w/FLYt5s=; b=r25sM+zJaFqMNlOmqY9UdO72MmwdPW6Vcj99AAsGvjcR2eGssrrkxc4Cg98jTuxVNvZjNs Pcbm/tbFKx8djMAA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 81E7E13A7E; Fri, 26 Aug 2022 21:45:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id bl+sH+w+CWOWWAAAMHmgww (envelope-from ); Fri, 26 Aug 2022 21:45:16 +0000 From: Martin Jambor To: Richard Sandiford , Richard Biener Cc: GCC Patches Subject: Re: [PATCH 2/2] vec: Add array_slice::bsearch In-Reply-To: References: <97EB95B8-B901-4290-AA80-3116209F9EBC@suse.de> User-Agent: Notmuch/0.35 (https://notmuchmail.org) Emacs/28.1 (x86_64-suse-linux-gnu) Date: Fri, 26 Aug 2022 23:45:16 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_SOFTFAIL,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: Hi, On Fri, Aug 26 2022, Richard Sandiford wrote: > 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<> bs= earch? > > 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. > OK, I can use std::lower_bound with simple lambdas too. The semantics of returning the first matching a criterion actually allows me to use it one more time. Martin