From nobody Mon Feb 9 19:07:49 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=1612600570; cv=none; d=zohomail.com; s=zohoarc; b=aliIoW2rbmdExCH6NKQWorm8AMGBE/IoHWlqhrKCp+agzO42xkXfCBvzVm+yKQV+tRU291y6bbITr2vmS4XJDf7K7aAfDK0ZZBgodMyOjvBb33qvpCJQM9l7VAblZnipAhLdX8wC6x5ie4x96hXJ+zcjXQlpXMJcwwlc7vDshxQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600570; 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=dZLnF9Axp/1383+QgeKFXQuaZks2vha5N23Haoo28pY=; b=lJrCs/6BlorzCjhq49AwSE3B2NzJZrcJnYBzlvI43NjUL6QwN827CaQflSUyt5fKaXzozqnhuLAC2dBz9o+rAmbkTTfk7GfzOEPHn0CNFzGqvCSKz3F46jWGOaZvYqy2bshIpQHcO/BGOkwW5l/s9wpVe8Ic9hvQa0rSmNpNfsM= 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 1612600570025398.56866099430215; Sat, 6 Feb 2021 00:36:10 -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-331-KlTMH7TNNBmqBnS9-Cu9MQ-1; Sat, 06 Feb 2021 03:33:53 -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 3BDE21DDE4; Sat, 6 Feb 2021 08:33:48 +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 187E262A23; 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 D542358088; Sat, 6 Feb 2021 08:33:47 +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 1168XkNT004955 for ; Sat, 6 Feb 2021 03:33:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id AB2FB60C77; Sat, 6 Feb 2021 08:33:46 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB0FF60C76 for ; Sat, 6 Feb 2021 08:33:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600569; 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=dZLnF9Axp/1383+QgeKFXQuaZks2vha5N23Haoo28pY=; b=hpr08ThYyNNDhvqAQS2XjGx/PUWB4fGcIEi+qwAXOS9mYxNLYHXuLYMJr+MBZDOYuMxgj9 Btv1POI9ESVLyzjs9CyR12yLT75qO4x795Tvvf8/WLzN/r3od7DZnur1eQzaDac1pwFlh2 I8/tuyyl8Gserx19WTtG/lngYAyyCKs= X-MC-Unique: KlTMH7TNNBmqBnS9-Cu9MQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 17/40] xenParseXLNamespaceData: Pre-calculate the length of array Date: Sat, 6 Feb 2021 09:32:39 +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" Precalculate the lenght to avoid use of 'virStringListAdd' in a loop. The code is also simplified by using APIs which don't return errors. Signed-off-by: Peter Krempa --- src/libxl/xen_xl.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c index 941832ce4e..a8af54a845 100644 --- a/src/libxl/xen_xl.c +++ b/src/libxl/xen_xl.c @@ -1150,33 +1150,36 @@ static int xenParseXLNamespaceData(virConfPtr conf, virDomainDefPtr def) { virConfValuePtr list =3D virConfGetValue(conf, "device_model_args"); - g_auto(GStrv) args =3D NULL; - size_t nargs; + virConfValuePtr next; + size_t nargs =3D 0; libxlDomainXmlNsDefPtr nsdata =3D NULL; + size_t n =3D 0; - if (list && list->type =3D=3D VIR_CONF_LIST) { - list =3D list->list; - while (list) { - if ((list->type !=3D VIR_CONF_STRING) || (list->str =3D=3D NUL= L)) { - list =3D list->next; - continue; - } + if (!list || list->type !=3D VIR_CONF_LIST) + return 0; - virStringListAdd(&args, list->str); - list =3D list->next; - } + list =3D list->list; + + for (next =3D list; next; next =3D next->next) { + if (next->type !=3D VIR_CONF_STRING || !next->str) + continue; + + nargs++; } - if (!args) + if (nargs =3D=3D 0) return 0; - nargs =3D g_strv_length(args); - if (nargs > 0) { - nsdata =3D g_new0(libxlDomainXmlNsDef, 1); + nsdata =3D g_new0(libxlDomainXmlNsDef, 1); + def->namespaceData =3D nsdata; + nsdata->args =3D g_new0(char *, nargs + 1); + nsdata->num_args =3D nargs; + + for (next =3D list; next; next =3D next->next) { + if (next->type !=3D VIR_CONF_STRING || !next->str) + continue; - nsdata->args =3D g_steal_pointer(&args); - nsdata->num_args =3D nargs; - def->namespaceData =3D nsdata; + nsdata->args[n++] =3D g_strdup(next->str); } return 0; --=20 2.29.2