public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Martin Jambor <mjambor@suse.cz>
Cc: Richard Sandiford <richard.sandiford@arm.com>,
	Richard Biener <rguenther@suse.de>,
	GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH 2/2] vec: Add array_slice::bsearch
Date: Sat, 27 Aug 2022 08:49:19 +0200	[thread overview]
Message-ID: <B1254077-F5C5-4E72-B6CA-1948905A3857@gmail.com> (raw)
In-Reply-To: <ri6a67q7k7n.fsf@suse.cz>



> Am 26.08.2022 um 23:45 schrieb Martin Jambor <mjambor@suse.cz>:
> 
> Hi,
> 
>> On Fri, Aug 26 2022, Richard Sandiford wrote:
>> Richard Biener <rguenther@suse.de> writes:
>>>> Am 26.08.2022 um 18:40 schrieb Martin Jambor <mjambor@suse.cz>:
>>>> 
>>>> Hi,
>>>> 
>>>> This adds a method to binary search in a sorted array_slice.
>>>> 
>>>> 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.
>>>> 
>>>> 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<> bsearch?
>> 
>> IMO it would be better to transition to using <algorithm> 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.

Can you try to compare generated code?

> Martin

  reply	other threads:[~2022-08-27  6:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-26 16:39 Martin Jambor
2022-08-26 18:24 ` Richard Biener
2022-08-26 20:23   ` Richard Sandiford
2022-08-26 21:45     ` Martin Jambor
2022-08-27  6:49       ` Richard Biener [this message]
2022-08-29 16:18         ` Martin Jambor
2022-08-26 20:32   ` Martin Jambor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=B1254077-F5C5-4E72-B6CA-1948905A3857@gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=mjambor@suse.cz \
    --cc=rguenther@suse.de \
    --cc=richard.sandiford@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).