From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS53758 23.128.96.0/24 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 535E21F8C6 for ; Sat, 28 Aug 2021 01:29:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232934AbhH1BaY (ORCPT ); Fri, 27 Aug 2021 21:30:24 -0400 Received: from pb-smtp21.pobox.com ([173.228.157.53]:55896 "EHLO pb-smtp21.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230238AbhH1BaX (ORCPT ); Fri, 27 Aug 2021 21:30:23 -0400 Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 46D5113821F; Fri, 27 Aug 2021 21:29:34 -0400 (EDT) (envelope-from junio@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=DP53HVhUBFctaKbKns52papUt9ds3AM6glsd9s /bzWg=; b=fDuzmZB8Or/EMa/eaw2KfVgx9oQye0/EsBerLdovlXM2pdDGydm6kY i54LeQkxqroshoGxFKbhGo3/dr6y5EBvgdRXA5ePcyDeHgBj2zpOh8d+p8FM4qUw OmAud4RUqV1jFep83YfsO1zcBvTsrV5Q1htDR1xGwnvbOUxZ1l8Hg= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 40A5913821E; Fri, 27 Aug 2021 21:29:34 -0400 (EDT) (envelope-from junio@pobox.com) Received: from pobox.com (unknown [34.74.116.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id 8E14413821C; Fri, 27 Aug 2021 21:29:31 -0400 (EDT) (envelope-from junio@pobox.com) From: Junio C Hamano To: =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason Cc: git@vger.kernel.org, Emily Shaffer , Derrick Stolee Subject: Re: [PATCH v3 2/5] strvec: add a strvec_pushvec() References: Date: Fri, 27 Aug 2021 18:29:30 -0700 In-Reply-To: (Junio C. Hamano's message of "Fri, 27 Aug 2021 18:23:26 -0700") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: 64EAE1EE-079F-11EC-B79D-9BA3EF469F85-77302942!pb-smtp21.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Junio C Hamano writes: >> +void strvec_pushvec(struct strvec *array, const struct strvec *items) >> +{ >> + int i; >> + >> + for (i = 0; i < items->nr; i++) >> + strvec_push(array, items->v[i]); >> +} > > This implementation is not wrong per-se, but is somewhat > disappointing. When items->nr is large, especially relative to the > original array->alloc, it would incur unnecessary reallocations that > we can easily avoid by pre-sizing the array before pushing the > elements of items from it. > > In the original code that became the first user of this helper, it > may not have made much difference, but now it is becoming a more > generally reusable API function, we should care. And if we do not care, you can rewrite the code that became the first user of this helper to instead call strvec_pushv() on the items->v array that is guaranteed to be NULL terminated, without inventing this new helper. I think I am fine with either way.