From nobody Mon Feb 9 16:02:45 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612600572; cv=none; d=zohomail.com; s=zohoarc; b=T1hIxZQenbMPR4w8NGmANLhj6JQCeEXxsV/M/37BcCyCULu6nqGsqM+Sib/S8wStdVcxJDd8g1WxTpLKjJWgenCkV2fiyIS9yi58PZC3bAROOYOdATqJeZ0Mpk/KoTEHD3CzbYKKhbB1MHJwXgHRJLeK6Z4NXG0U+Pu++bNogcE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600572; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XIe6Fa/2tmvj/xUYlsok8doQzKTR7bBfJ5aLkz4EY1s=; b=BZl2g+KHHy5wRwfCEo3IcnGaXh9/sGLsXNv3IeXZ9rJk41thRcGWfUDbPzzXIH3+bJ2kEEexOdE7uy+UUXqAGnTeYxjfHwxnxoJ/E5mGMdgEcKcMc7qBXVyWj89OfnyOx7J91+p8inmFz7Yv4ean469JpxIL9zjPiy3C53f0eTU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1612600572873182.46482450802546; Sat, 6 Feb 2021 00:36:12 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-233-8rAk1GMvN-OEXp0NJc_Yxg-1; Sat, 06 Feb 2021 03:33:52 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B1BB2192AB79; Sat, 6 Feb 2021 08:33:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8D95E62A0C; Sat, 6 Feb 2021 08:33:45 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 571E358080; Sat, 6 Feb 2021 08:33:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1168XSIR004784 for ; Sat, 6 Feb 2021 03:33:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id C517660C78; Sat, 6 Feb 2021 08:33:28 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0788860C77 for ; Sat, 6 Feb 2021 08:33:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600571; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=XIe6Fa/2tmvj/xUYlsok8doQzKTR7bBfJ5aLkz4EY1s=; b=GUG8oFdw7CJWCPL9P0cYvIwPbMLnP/sSuWnfzfrXE4lXr1KcF39ZOcm9Frr1Kd1XARlsvd qkn3gN0vEWLduE1cpIrw56XMpwwIaoH90nJbFvAQ+NI5utEwhmeVpRJF/EPJvdW7GBSOYj q7WzEBAkl5Ftmso3NTvvcjgo6SUvWiY= X-MC-Unique: 8rAk1GMvN-OEXp0NJc_Yxg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 12/40] x86ModelParseFeatures: Don't construct list using 'virStringListAdd' Date: Sat, 6 Feb 2021 09:32:34 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Pre-allocate the list to the upper bound and fill it gradually. Since the data is kept long-term and the list won't be populated much shrink it to the actual size after parsing. While using 'virStringListAdd' here wouldn't be as expensive as this function is used just once, the removal will allow to remove 'virStringListAdd' altogether to discourage the antipattern it promotes. Signed-off-by: Peter Krempa --- src/cpu/cpu_x86.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 2422e258ec..a64a971540 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -1604,11 +1604,14 @@ x86ModelParseFeatures(virCPUx86ModelPtr model, { g_autofree xmlNodePtr *nodes =3D NULL; size_t i; + size_t nremoved =3D 0; int n; if ((n =3D virXPathNodeSet("./feature", ctxt, &nodes)) <=3D 0) return n; + model->removedFeatures =3D g_new0(char *, n + 1); + for (i =3D 0; i < n; i++) { g_autofree char *ftname =3D NULL; g_autofree char *removed =3D NULL; @@ -1640,8 +1643,7 @@ x86ModelParseFeatures(virCPUx86ModelPtr model, } if (rem =3D=3D VIR_TRISTATE_BOOL_YES) { - if (virStringListAdd(&model->removedFeatures, ftname) < 0) - return -1; + model->removedFeatures[nremoved++] =3D g_strdup(ftname); continue; } } @@ -1650,6 +1652,8 @@ x86ModelParseFeatures(virCPUx86ModelPtr model, return -1; } + model->removedFeatures =3D g_renew(char *, model->removedFeatures, nre= moved + 1); + return 0; } --=20 2.29.2