From nobody Mon Feb 9 17:24:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1612600816; cv=none; d=zohomail.com; s=zohoarc; b=OXuNHZcjpKLQVVUUEVU0xxN4laLXbedFaIZK50gZI9Lh0hIJp8GvQNkg46aRoc9QQrrBaIfFmr8F7USyPuIm2Fgj4Wb9ESZeD1nDReKrxNOZhK2hOlOQwZ8OhDD7U0kHnmFLjs2lchec0jVBor63i0eL8XZcmmHIj/q3Oaulu28= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600816; 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=72GNEN85R9t7A81FcG5kHzrduS10kd48Q3/glmREC/k=; b=WJuTci2bvkem5nL2fFuCLhdgXU/bWx+v/uOcwj96SaUEaLnye07j7Cyb8WvkuUkOfTsSDD8PuMOv3WCr7RozIGXa/YciDTsMfYmXRtmFdJlwa0gJ970qi5REnNqUyOY8FmHpWBfDtrUmZ3cMd/xEJf3MNggLiPGUQCQSCEJzclY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 161260081643154.09430019331171; Sat, 6 Feb 2021 00:40:16 -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-412-CjTPEQ1COICbYNIkdnvrXg-1; Sat, 06 Feb 2021 03:33:54 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 943701DDE5; Sat, 6 Feb 2021 08:33:48 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 682D319C47; Sat, 6 Feb 2021 08:33:48 +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 308A0180881C; Sat, 6 Feb 2021 08:33:48 +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 1168XXp9004864 for ; Sat, 6 Feb 2021 03:33:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id EA1A360C78; Sat, 6 Feb 2021 08:33:33 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 38A5B60C77 for ; Sat, 6 Feb 2021 08:33:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600815; 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=72GNEN85R9t7A81FcG5kHzrduS10kd48Q3/glmREC/k=; b=fCA4x62r/Uvnn92cSO0zo03uuRDRVYZJn1cmwWfkm3GZyl+QlF0dmdACS/YpZQ0Gk3BYgx 3hS5dIG9+CdQTqM6oPCyiBzU/ss2gzh5fMupMOarf6ELo3QEQMUkYrVdduHRMue2iyvJwk atUh6d3LfX1fgpuzzB4/yXw3DluynOg= X-MC-Unique: CjTPEQ1COICbYNIkdnvrXg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 14/40] virResctrlMonitorGetStats: Don't use 'virStringListAdd' Date: Sat, 6 Feb 2021 09:32:36 +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.84 on 10.5.11.23 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" The iner loop copies the 'resources' array multiple times using 'virStringListAdd' which has O(n^2) complexity. Pre-calculate the length so we can allocate the array upfront and just copy the strings in the loop. Signed-off-by: Peter Krempa --- src/util/virresctrl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 86b4b9d73b..ab35bccfc5 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -2662,6 +2662,7 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monito= r, char *filepath =3D NULL; struct dirent *ent =3D NULL; virResctrlMonitorStatsPtr stat =3D NULL; + size_t nresources =3D g_strv_length((char **) resources); if (!monitor) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -2705,6 +2706,7 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monito= r, continue; stat =3D g_new0(virResctrlMonitorStats, 1); + stat->features =3D g_new0(char *, nresources + 1); /* The node ID number should be here, parsing it. */ if (virStrToLong_uip(node_id, NULL, 0, &stat->id) < 0) @@ -2724,8 +2726,7 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monito= r, if (VIR_APPEND_ELEMENT(stat->vals, stat->nvals, val) < 0) goto cleanup; - if (virStringListAdd(&stat->features, resources[i]) < 0) - goto cleanup; + stat->features[i] =3D g_strdup(resources[i]); } if (VIR_APPEND_ELEMENT(*stats, *nstats, stat) < 0) --=20 2.29.2