Re: [PATCH 4/4] gdb: change regcache list to be a map

Simon Marchi
2020-08-05T20:25:37Z

On 2020-08-05 2:02 p.m., Pedro Alves wrote:
> On 7/30/20 6:03 PM, Simon Marchi wrote:
>> On 2020-07-30 12:58 p.m., Simon Marchi wrote:
>>> It's down to:
>>>
>>> for (auto it = regcaches.begin (); it != regcaches.end ();)
>>> {
>>> if (it->second->target () == target)
>>> it = regcaches.erase (it);
>>> else
>>> it++;
>>> }
>> Ah, I see that you've provided me a patch for that too (I thought you only
>> did the multi-level map thing).
> Note that it's idiomatic to write ++it instead of it++, to avoid
> creating a temporary. It's possible that compilers nowadays optimize
> it away, but it still looks odd to not write ++it to me.

Ack.

>
> Your code is:
>> for (auto it = regcaches.begin (); it != regcaches.end ();)
>> {
>> if (it->second->target () == target)
>> {
>> delete it->second;
>> it = regcaches.erase (it);
>> }
>> }
>>
>> I think you are missing an it++ in the else? Otherwise, when the target doesn't
>> match, we'll get into an infinite loop I presume.
> Yes, I was. I didn't notice because I jumped straight to the multi-map
> patch on top, which deletes that code, IIRC.
>
Thanks.

Simon