From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1964 invoked by alias); 26 Sep 2019 11:33:43 -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 1789 invoked by uid 89); 26 Sep 2019 11:33:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-wm1-f42.google.com Received: from mail-wm1-f42.google.com (HELO mail-wm1-f42.google.com) (209.85.128.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 26 Sep 2019 11:33:41 +0000 Received: by mail-wm1-f42.google.com with SMTP id 3so2192464wmi.3 for ; Thu, 26 Sep 2019 04:33:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ha1FIX2oD6u4qMZLgkALHUXWN/ByWCBsVMzVuiq89LY=; b=INYO5JHMsRV/8fK5qFLJFtsR4uwtQL/0YnYqD69WLyXeapU6Yad8Ss1L6MVrMpdYbg U7/lk7vKJ4KmOr8jjLs5VvrhgnvonVYezj1hNR9Xm/eP1t8tccPRILV1269ZpeqlAxbx yde2+EK5G0/COb/Hf8SbKe18EQBMFqOP206msAuBTFl2hGXve5xSbQYs5B7Ep/tghzWC /an3nzZkHhHP3T8xxyIXobQxr0ZyYZpk2cPTqLaRuaPRfmValPvBCzKEi/n6pjvQFiaJ Si7o+c+KJ/djP6SHzgqVgsR95NzVN8FDHxWM6NTln+BhWi7PVn7SGyCH/d3zf1+HCm0/ Xbwg== Return-Path: Received: from localhost (host86-128-12-122.range86-128.btcentralplus.com. [86.128.12.122]) by smtp.gmail.com with ESMTPSA id z125sm4160844wme.37.2019.09.26.04.33.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Sep 2019 04:33:39 -0700 (PDT) Date: Thu, 26 Sep 2019 11:33:00 -0000 From: Andrew Burgess To: "Metzger, Markus T" Cc: gdb-patches , Simon Marchi , Tom Tromey Subject: Re: [PATCHv3 2/3] gdb: Change a VEC to std::vector in btrace.{c,h} Message-ID: <20190926113338.GT4962@embecosm.com> References: <87lfucf2qs.fsf@tromey.com> <6ceaca2e6d37e8bfd913ab787229cbd2d3a7110d.1569455610.git.andrew.burgess@embecosm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Fortune: Are you mentally here at Pizza Hut?? X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes X-SW-Source: 2019-09/txt/msg00511.txt.bz2 * Metzger, Markus T [2019-09-26 08:47:28 +0000]: > Hello Andrew, > > > @@ -2986,8 +2986,10 @@ btrace_maint_decode_pt (struct btrace_maint_info > > *maint, > > if (maint_btrace_pt_skip_pad == 0 || packet.packet.type != ppt_pad) > > { > > packet.errcode = pt_errcode (errcode); > > - VEC_safe_push (btrace_pt_packet_s, maint->variant.pt.packets, > > - &packet); > > + if (maint->variant.pt.packets == NULL) > > + maint->variant.pt.packets > > + = new std::vector ; > > + maint->variant.pt.packets->push_back (packet); > > We shouldn't do that check inside the loop. I used VEC_safe_push > for the realloc aspect. Thanks, I pushed the vector allocation out of the loop. > > > > @@ -3098,11 +3101,13 @@ btrace_maint_update_packets (struct > > btrace_thread_info *btinfo, > > > > #if defined (HAVE_LIBIPT) > > case BTRACE_FORMAT_PT: > > - if (VEC_empty (btrace_pt_packet_s, btinfo->maint.variant.pt.packets)) > > + if (btinfo->maint.variant.pt.packets == nullptr > > + || btinfo->maint.variant.pt.packets->empty ()) > > btrace_maint_update_pt_packets (btinfo); > > Here, I'd check for nullptr in order to allocate the vector and call > btrace_maint_update_pt_packets. Afterwards, I'd check for emptiness and delete > the vector again if there are no packets. > > We can also leave an empty vector if you prefer that. I hope I've interpreted your suggestion correctly. Please do check my next version and correct me if I've not understood you. Thanks, Andrew > > Regards, > Markus. > > Intel Deutschland GmbH > Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany > Tel: +49 89 99 8853-0, www.intel.de > Managing Directors: Christin Eisenschmid, Gary Kershaw > Chairperson of the Supervisory Board: Nicole Lau > Registered Office: Munich > Commercial Register: Amtsgericht Muenchen HRB 186928 >