Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Pedro Alves <palves@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Use an std::vector for inline_states
Date: Sat, 07 Apr 2018 21:13:00 -0000	[thread overview]
Message-ID: <9779f6419f21cccebbc3336dc488f17d@polymtl.ca> (raw)
In-Reply-To: <6bcda047-7dbd-79ed-8eec-2bd5d59f6749@redhat.com>

On 2018-04-07 15:28, Pedro Alves wrote:
> On 04/07/2018 03:42 PM, Simon Marchi wrote:
> 
>>  /* Locate saved inlined frame state for PTID, if it exists
>>     and is valid.  */
>> @@ -66,43 +70,29 @@ static VEC(inline_state_s) *inline_states;
>>  static struct inline_state *
>>  find_inline_frame_state (ptid_t ptid)
>>  {
> 
>> -	  if (current_pc != state->saved_pc)
>> -	    {
>> -	      /* PC has changed - this context is invalid.  Use the
>> -		 default behavior.  */
>> -	      VEC_unordered_remove (inline_state_s, inline_states, ix);
>> -	      return NULL;
> 
> ...
> 
>> -  state = VEC_safe_push (inline_state_s, inline_states, NULL);
>> -  memset (state, 0, sizeof (*state));
>> -  state->ptid = ptid;
>> +      inline_states.erase (state_it);
> 
> The patch looks good, though it made me realize that when we're
> replacing VEC_unordered_remove with std::vector::erase, we're 
> introducing
> a pessimization, which makes me ponder about having an 
> utility/replacement
> for VEC_unordered_remove that works with std::vector and alikes.
> I.e., a function that removes an element from a vector simply by moving
> the last element to the now-vacant position.  That's more efficient
> than erase, because it avoids having to copy/move the remaining
> elements, making it O(1).
> 
> Something like:
> 
>  template<typename Vector>
>  void
>  unordered_erase (Vector &v, typename Vector::const_iterator pos)
>  {
>      *pos = std::move (v.back ());
>      v.pop_back ();
>  }

We actually have almost that already in common/gdb_vecs.h.  And I have 
no excuse not to know about it, since I added it.

I'll review my latest patches to see if there are more opportunities to 
use that.

Thanks,

Simon


  reply	other threads:[~2018-04-07 21:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-07 14:42 Simon Marchi
2018-04-07 19:28 ` Pedro Alves
2018-04-07 21:13   ` Simon Marchi [this message]
2018-04-07 23:21   ` Simon Marchi
2018-04-08 17:29     ` Pedro Alves
2018-04-09  9:10       ` Pedro Alves
2018-04-09 19:45         ` Simon Marchi

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=9779f6419f21cccebbc3336dc488f17d@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.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