From nobody Mon Feb 9 19:07:41 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=1612600449; cv=none; d=zohomail.com; s=zohoarc; b=YXgUKuRjJrQMMH+kkn3AwrFzUex0yPS/9UZQRkk4N1CLSFazLIOSmo8jmvrmcxf1pVESfLe5rvgJXy2wacWVMSk689sTBg008dT3e6TD8t3fG348honBlgFIzWWKQBJ5fnzI02nmy6Q7sIvRU7kXK4wv+IQNQ5wU2WoYVQud+U4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600449; 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=LtPEaKGQSdbVtV54ymNhqs5piM2fFDnK33NyEUqyiD4=; b=XbCgOHW9o+LarWHRsS2Nnpx8jZ0uLA88tuzp1gn6BNms36c/tDKi580B1EofdykwJ3G9Su62hdj7QVFSh3gX3xpfyu42Hs6F2ex8XCyVDf6J0Z4l/5x5UtO4XtrRl/AvKJlyVyY14S95TxCFhXhGFTLa5D4ZlTjxPSJ5f/Zkh+w= 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 1612600449686267.8976438557876; Sat, 6 Feb 2021 00:34:09 -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-279-9WTw6H2aPhG8GDCEj05OSw-1; Sat, 06 Feb 2021 03:34:06 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DC95D1005501; Sat, 6 Feb 2021 08:34:00 +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 B76FE1010F4E; Sat, 6 Feb 2021 08:34:00 +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 7F99258078; Sat, 6 Feb 2021 08:34:00 +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 1168XwK5005120 for ; Sat, 6 Feb 2021 03:33:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id EE77E60C76; Sat, 6 Feb 2021 08:33:58 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DDD960C77 for ; Sat, 6 Feb 2021 08:33:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600448; 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=LtPEaKGQSdbVtV54ymNhqs5piM2fFDnK33NyEUqyiD4=; b=X3U/2TQ+yx/cw5jyXbrKIw010JDIh/WG15/KsDDSa7qv0ndkbaMH2uOYQCO3jytyDdpjkJ 792rK6ozEB7wKyM7EVy+af61DPSc2Kr/RXL+g/DecL43WKwqBjSkSGT39EvVTyZpbOL0fY qF2XvDbBvyorYxHIVAGq1jhhLrSSuKg= X-MC-Unique: 9WTw6H2aPhG8GDCEj05OSw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 21/40] util: virstring: Remove virStringListAdd and virStringListRemove Date: Sat, 6 Feb 2021 09:32:43 +0100 Message-Id: <03d32765f2b5b9c1bbad37ea506a658d105303d7.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.22 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 hides the fact that a O(n) count of elements is performed every time it's called which makes it inefficient. Stop supporting such semantics and remove the helpers. Users have a choice of using GSList or an array with a counter variable rather than repeated lookups. Signed-off-by: Peter Krempa --- src/libvirt_private.syms | 2 -- src/util/virstring.c | 61 ---------------------------------- src/util/virstring.h | 5 --- tests/virstringtest.c | 72 ---------------------------------------- 4 files changed, 140 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c2270208e4..86380d0853 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3240,14 +3240,12 @@ virStringHasControlChars; virStringHasSuffix; virStringIsEmpty; virStringIsPrintable; -virStringListAdd; virStringListFreeCount; virStringListGetFirstWithPrefix; virStringListHasString; virStringListJoin; virStringListLength; virStringListMerge; -virStringListRemove; virStringMatch; virStringMatchesNameSuffix; virStringParsePort; diff --git a/src/util/virstring.c b/src/util/virstring.c index 521f2de3f6..bf861d4847 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -162,67 +162,6 @@ char *virStringListJoin(const char **strings, } -/** - * virStringListAdd: - * @strings: a NULL-terminated array of strings - * @item: string to add - * - * Appends @item into string list @strings. If *@strings is not - * allocated yet new string list is created. - * - * Returns: 0 on success, - * -1 otherwise - */ -int -virStringListAdd(char ***strings, - const char *item) -{ - size_t i =3D virStringListLength((const char **) *strings); - - if (VIR_EXPAND_N(*strings, i, 2) < 0) - return -1; - - (*strings)[i - 2] =3D g_strdup(item); - - return 0; -} - - -/** - * virStringListRemove: - * @strings: a NULL-terminated array of strings - * @item: string to remove - * - * Remove every occurrence of @item in list of @strings. - */ -void -virStringListRemove(char ***strings, - const char *item) -{ - size_t r, w =3D 0; - - if (!strings || !*strings) - return; - - for (r =3D 0; (*strings)[r]; r++) { - if (STREQ((*strings)[r], item)) { - VIR_FREE((*strings)[r]); - continue; - } - if (r !=3D w) - (*strings)[w] =3D (*strings)[r]; - w++; - } - - if (w =3D=3D 0) { - VIR_FREE(*strings); - } else { - (*strings)[w] =3D NULL; - ignore_value(VIR_REALLOC_N(*strings, w + 1)); - } -} - - /** * virStringListMerge: * @dst: a NULL-terminated array of strings to expand diff --git a/src/util/virstring.h b/src/util/virstring.h index cfd24f0b74..00c669b43b 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -37,11 +37,6 @@ char *virStringListJoin(const char **strings, const char *delim) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); -int virStringListAdd(char ***strings, - const char *item); -void virStringListRemove(char ***strings, - const char *item); - int virStringListMerge(char ***dst, char ***src); diff --git a/tests/virstringtest.c b/tests/virstringtest.c index 7305190691..9eabb5b299 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -163,74 +163,6 @@ static int testJoin(const void *args) } -static int testAdd(const void *args) -{ - const struct testJoinData *data =3D args; - char **list =3D NULL; - char *got =3D NULL; - int ret =3D -1; - size_t i; - - for (i =3D 0; data->tokens[i]; i++) { - if (virStringListAdd(&list, data->tokens[i]) < 0) - goto cleanup; - } - - if (!list) - list =3D g_new0(char *, 1); - - if (!(got =3D virStringListJoin((const char **)list, data->delim))) { - VIR_DEBUG("Got no result"); - goto cleanup; - } - - if (STRNEQ(got, data->string)) { - fprintf(stderr, "Mismatch '%s' vs '%s'\n", got, data->string); - goto cleanup; - } - - ret =3D 0; - cleanup: - g_strfreev(list); - VIR_FREE(got); - return ret; -} - - -static int testRemove(const void *args) -{ - const struct testSplitData *data =3D args; - char **list =3D NULL; - size_t ntokens; - size_t i; - int ret =3D -1; - - if (!(list =3D virStringSplitCount(data->string, data->delim, - data->max_tokens, &ntokens))) { - VIR_DEBUG("Got no tokens at all"); - return -1; - } - - for (i =3D 0; data->tokens[i]; i++) { - virStringListRemove(&list, data->tokens[i]); - if (virStringListHasString((const char **) list, data->tokens[i]))= { - fprintf(stderr, "Not removed %s", data->tokens[i]); - goto cleanup; - } - } - - if (list && list[0]) { - fprintf(stderr, "Not removed all tokens: %s", list[0]); - goto cleanup; - } - - ret =3D 0; - cleanup: - g_strfreev(list); - return ret; -} - - static int testStringSortCompare(const void *opaque G_GNUC_UNUSED) { @@ -683,10 +615,6 @@ mymain(void) ret =3D -1; \ if (virTestRun("Join " #str, testJoin, &joinData) < 0) \ ret =3D -1; \ - if (virTestRun("Add " #str, testAdd, &joinData) < 0) \ - ret =3D -1; \ - if (virTestRun("Remove " #str, testRemove, &splitData) < 0) \ - ret =3D -1; \ } while (0) VIR_WARNINGS_NO_DECLARATION_AFTER_STATEMENT --=20 2.29.2