From nobody Tue Feb 10 07:40:42 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=1612600566; cv=none; d=zohomail.com; s=zohoarc; b=kpL2BZOdUrcOp2RcZ5KRV/6nnBIPxfKXA5CKS7HLejhJSw+zlmDmrw7GanLzFbGYh+fRud8nbpMHJqinkXl3LlesQEVT9vAYWu1Hc9UNsnc9o2I1GhndM4kW1GtUSEPpJte1BrtXbLop9J+0ur2tjYD2Nuoy3szIgAclwXXfJKg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600566; 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=E8gIBtONm8chYTud8Eb9jIT4lPlIRmkUqEthfWCyQMA=; b=GjjsVVCK4NCGV6Q5UILUS24NsBsIConvqMHK7JKgeYOgWZOQBYJGJ2bpBlwUeqF8UOU3A/8ujPBPkrocVdI8+elHNeUCPACwWWc6H2HiuoRRRZIZQWsKWINT7sKb8lA2Ro2zoUKJPeA0S7nvCyWRwJgoscVXMVv6jLgmdN0ZDEw= 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 1612600566204173.2203473101997; Sat, 6 Feb 2021 00:36:06 -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-239-3PMwcYseO0CNzR9GH5lnUw-1; Sat, 06 Feb 2021 03:33:46 -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 635B91DDE5; Sat, 6 Feb 2021 08:33:40 +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 3C90719C47; Sat, 6 Feb 2021 08:33:40 +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 08C5D18089CC; Sat, 6 Feb 2021 08:33:40 +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 1168XLn0004740 for ; Sat, 6 Feb 2021 03:33:21 -0500 Received: by smtp.corp.redhat.com (Postfix) id B3F8060C78; Sat, 6 Feb 2021 08:33:21 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D4D560C77 for ; Sat, 6 Feb 2021 08:33:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600565; 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=E8gIBtONm8chYTud8Eb9jIT4lPlIRmkUqEthfWCyQMA=; b=Wzxeyi8G+xfe4MY4kT9vKml8Vb/dbokl8PTJON7++8OLhdbvL68xyA5WrM8V0uoACoY21Z U+XxGf+I4zMzAWgjGFPbwJnqzw349WcrWPuV6NNxbM9V3hTBE0B3xQBwUo05D7XpEvtPsq fK1UASpiALUHhn299UoaoX6rEMKW8eY= X-MC-Unique: 3PMwcYseO0CNzR9GH5lnUw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 09/40] virHookCall: Don't use 'virStringListAdd' to construct list in loop Date: Sat, 6 Feb 2021 09:32:31 +0100 Message-Id: <4fe135233bd08fee668eb411e2464ab47a0e277c.1612599659.git.pkrempa@redhat.com> 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" 'virStringListAdd' calculates the string list length on every invocation so constructing a string list using it results in O(n^2) complexity. Signed-off-by: Peter Krempa --- src/util/virhook.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/util/virhook.c b/src/util/virhook.c index 05d46f259e..e4e1945225 100644 --- a/src/util/virhook.c +++ b/src/util/virhook.c @@ -34,6 +34,7 @@ #include "configmake.h" #include "vircommand.h" #include "virstring.h" +#include "virglibutil.h" #define VIR_FROM_THIS VIR_FROM_HOOK @@ -343,11 +344,11 @@ virHookCall(int driver, struct dirent *entry; g_autofree char *path =3D NULL; g_autofree char *dir_path =3D NULL; - g_auto(GStrv) entries =3D NULL; + g_autoptr(virGSListString) entries =3D NULL; const char *drvstr; const char *opstr; const char *subopstr; - size_t i, nentries; + GSList *next; if (output) *output =3D NULL; @@ -433,7 +434,7 @@ virHookCall(int driver, if (!virFileIsExecutable(entry_path)) continue; - virStringListAdd(&entries, entry_path); + entries =3D g_slist_prepend(entries, g_steal_pointer(&entry_path)); } if (ret < 0) @@ -442,18 +443,18 @@ virHookCall(int driver, if (!entries) return script_ret; - nentries =3D virStringListLength((const char **)entries); - qsort(entries, nentries, sizeof(*entries), virStringSortCompare); + entries =3D g_slist_sort(entries, (GCompareFunc) strcmp); - for (i =3D 0; i < nentries; i++) { + for (next =3D entries; next; next =3D next->next) { int entry_ret; const char *entry_input; g_autofree char *entry_output =3D NULL; + const char *filename =3D next->data; /* Get input from previous output */ entry_input =3D (!script_ret && output && !virStringIsEmpty(*output)) ? *output : input; - entry_ret =3D virRunScript(entries[i], id, opstr, + entry_ret =3D virRunScript(filename, id, opstr, subopstr, extra, entry_input, (output) ? &entry_output : NULL); if (entry_ret < script_ret) --=20 2.29.2