From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 44931 invoked by alias); 7 Apr 2018 21:13:45 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 44921 invoked by uid 89); 7 Apr 2018 21:13:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 07 Apr 2018 21:13:43 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id w37LDagj021995 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 7 Apr 2018 17:13:41 -0400 Received: by simark.ca (Postfix, from userid 112) id 600221EF60; Sat, 7 Apr 2018 17:13:36 -0400 (EDT) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id B029C1E4B5; Sat, 7 Apr 2018 17:13:34 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Sat, 07 Apr 2018 21:13:00 -0000 From: Simon Marchi To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] Use an std::vector for inline_states In-Reply-To: <6bcda047-7dbd-79ed-8eec-2bd5d59f6749@redhat.com> References: <20180407144205.20909-1-simon.marchi@polymtl.ca> <6bcda047-7dbd-79ed-8eec-2bd5d59f6749@redhat.com> Message-ID: <9779f6419f21cccebbc3336dc488f17d@polymtl.ca> X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.4 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Sat, 7 Apr 2018 21:13:36 +0000 X-IsSubscribed: yes X-SW-Source: 2018-04/txt/msg00131.txt.bz2 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 > 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