From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id C16773858401 for ; Sat, 27 Aug 2022 06:49:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C16773858401 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x635.google.com with SMTP id cu2so6765390ejb.0 for ; Fri, 26 Aug 2022 23:49:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:from:to:cc; bh=3Rc18jHZkc539O1hNtmVrVLSBl1sYicumoDZWtCmrZo=; b=TungMWrMvYQ2MuYdpca+yL9QbKDPQGZbxgvCwEfQ4aBj6yMcwBszfWwnHrsQoNNOvc GMgOZ7MsrobUQToBVeULn18ynn9wXVpK5cYtb51BL29SKMi0OHbqlpRCf/aENXXs6g58 ktMQZ3Y1miSzvcdOeXp28idVcQLr/LAOJUxSvUzl3ra7fw4kxhK/oJMmd5Bc061ZDQJi l6L7Ror29JgiYHMMphNJzhvtF1eJaQwEf5hdOIdnN+JbO7H5n+GbS4z86GV25I5YIwBX ZgplRFi5bJUCfEEM7n2N6/hBOdIVYGJHVAhMDvFtxzFZg0+yHG7CeMuRKtRQp9IQMt3J XIHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:x-gm-message-state:from:to:cc; bh=3Rc18jHZkc539O1hNtmVrVLSBl1sYicumoDZWtCmrZo=; b=yx3wiJd3OYSF1D2Lj7X5cSqzQ/dgu4J55aEJu8mbU7MQw946RkALkjrsl6kDsmWvq5 Sgo2bYpsGinK3ARBJJ4IApQZ5p5I62DgYHSyHqESNF1olnntGqAy1yKfj1eLUFhLgwc6 ZywS8/JO5tKwVLSuzDnmPsjmlwobuNkSQ94QHfkiBlB8iciElV4n6yrn8w9YdfOpdKm6 Cl4y4GClim/PlyjkwZ+iQfl5B8+RceSsV2IgoDHudlBvVfd4b8k9+pottpHTeihqQR4e sS2EmAokk7MQvKwkG+H9NsEA4y3qYtSMjdnRObV+NVmlpY1OsnRygGMq/YjmBmlrtKwx RhsA== X-Gm-Message-State: ACgBeo2zMGRWRhuf+cKSBJiZcav9s6r1RlfzE0a1ipe8Vac2WhMn3uPd XiVTsXtTemGz+HU+oUOu7fQ= X-Google-Smtp-Source: AA6agR5J3BE0jIbk+/ho0t7hTiqfjnwLonDI5WEye4FggTVmPfeVJxGk8Js//A0OrWp0RdOpTKAkoA== X-Received: by 2002:a17:907:3e90:b0:73c:fdd2:3904 with SMTP id hs16-20020a1709073e9000b0073cfdd23904mr7309976ejc.455.1661582960533; Fri, 26 Aug 2022 23:49:20 -0700 (PDT) Received: from smtpclient.apple (dynamic-077-004-048-053.77.4.pool.telefonica.de. [77.4.48.53]) by smtp.gmail.com with ESMTPSA id f8-20020a170906494800b0073d68db09ecsm1745540ejt.23.2022.08.26.23.49.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Aug 2022 23:49:19 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Richard Biener Mime-Version: 1.0 (1.0) Subject: Re: [PATCH 2/2] vec: Add array_slice::bsearch Date: Sat, 27 Aug 2022 08:49:19 +0200 Message-Id: References: Cc: Richard Sandiford , Richard Biener , GCC Patches In-Reply-To: To: Martin Jambor X-Mailer: iPhone Mail (19G82) X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: > Am 26.08.2022 um 23:45 schrieb Martin Jambor : >=20 > =EF=BB=BFHi, >=20 >> 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? >>>=20 >>> Can you avoid the copying by using array slice bsearch from the vec<> bs= earch? >>=20 >> 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. >>=20 >> 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. >>=20 >=20 > 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. Can you try to compare generated code? > Martin