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.7 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 3FF2C1F852 for ; Sat, 29 Jan 2022 05:06:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229958AbiA2FGl (ORCPT ); Sat, 29 Jan 2022 00:06:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229736AbiA2FGl (ORCPT ); Sat, 29 Jan 2022 00:06:41 -0500 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3302C061714 for ; Fri, 28 Jan 2022 21:06:40 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id w14so14241687edd.10 for ; Fri, 28 Jan 2022 21:06:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hUAQtl1CYOXV0SfOSKa0MXxaWDh9/rnxIWDDpZOhoA8=; b=KL+RUgoafNgHdVsMQbGiU0fICGjDOtWUnQ5wiNXSTqbgEQWh3PAtgulBQuU+RwlqkC hDI0qL5cNX6M4O86iPxMvgcrF5LV33Hab5PyxT2tIbB2xXSiCU4/NsTUSUt7Utoi0KI2 /qaQU0rOeBgSgUaktrzwzV6MfnKYyc+RRT836KZd1Gs2VaqTDJoHPSfnzu81Xq0jtGOX XM4UhgOTWvSB25Urwl9JErAE+AiAIHL/PKj7gYsucuK+/1VGkqVp3ry4Fn70Uhol4ZYU h+07PUNdhdko+aK58Vyzb/ueNBgA7vDZM3o48m4YllwI3UjYQdjnlByBXYj780/xHSjm LosA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hUAQtl1CYOXV0SfOSKa0MXxaWDh9/rnxIWDDpZOhoA8=; b=A+9k9M3GSe/IF3TN9oThzzni1UWHDFg7CFAsAj4f04NhvVBD5JXPT/qVEgmUR1mbJ6 GvJoDpwzALembKNfgkhWlpyCkBOOlCNoMyvRl2Cgaih+RKoIC6C4DpGqW3qc0MdH/mcv DuvmRET+DdfjbCih2H0tLqGo122iawYske+IDwnBKI43eiuMIaSF/Oue9UyNVgsFTSUG fsIESHVGYZgqmOhc9GwWf6gSsfrilQ2fJfNSKMdgZAlLnYiOuvcJnUWTZeRNfzv+2Xqx A5ibnNYpjb5crDU5Q8zYbMMC0l09ltf4QQvyzmSt9nCGSooQia9FLZerisc9SIHMDJGx g41Q== X-Gm-Message-State: AOAM533FSi6a4PtBZJh6vacHTjdT/1RA5a2mndze0cCqQR5QTy5f5XO7 Yzbg+EPxoA+k8GGyi30sM+mjW8gjni7twjICGeY= X-Google-Smtp-Source: ABdhPJxbwy7ObS7aGudj81EKFplPMv/7CU+DxxLeJJ2zAtSr1rBwOHDKcMTkezNvHm8Pl7fcC3rJljgR5LeRrotHdps= X-Received: by 2002:aa7:d949:: with SMTP id l9mr11468753eds.153.1643432799267; Fri, 28 Jan 2022 21:06:39 -0800 (PST) MIME-Version: 1.0 References: <35e0ed9271a0229fe2acd2385a7e4171d4dfe077.1642888562.git.gitgitgadget@gmail.com> In-Reply-To: From: Elijah Newren Date: Fri, 28 Jan 2022 21:06:28 -0800 Message-ID: Subject: Re: [PATCH 08/12] merge-ort: provide a merge_get_conflicted_files() helper function To: Christian Couder Cc: Elijah Newren via GitGitGadget , git , Christian Couder , Taylor Blau , Johannes Altmanninger , Ramsay Jones , Johannes Schindelin , =?UTF-8?Q?Ren=C3=A9_Scharfe?= Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Wed, Jan 26, 2022 at 3:07 AM Christian Couder wrote: > > On Sat, Jan 22, 2022 at 10:56 PM Elijah Newren via GitGitGadget > wrote: > > > +void merge_get_conflicted_files(struct merge_result *result, > > + struct string_list *conflicted_files) > > +{ > > + struct hashmap_iter iter; > > + struct strmap_entry *e; > > + struct merge_options_internal *opti = result->priv; > > + > > + strmap_for_each_entry(&opti->conflicted, &iter, e) { > > + const char *path = e->key; > > + struct conflict_info *ci = e->value; > > + int i; > > + > > + VERIFY_CI(ci); > > + > > + for (i = MERGE_BASE; i <= MERGE_SIDE2; i++) { > > + struct stage_info *si; > > + > > + if (!(ci->filemask & (1ul << i))) > > + continue; > > + > > + si = xmalloc(sizeof(*si)); > > It's probably a premature optimization, so feel free to ignore, but as > MERGE_BASE and MERGE_SIDE2 are constants, and ci->filemask is constant > inside the 'for' loop, we could compute before the 'for' loop how many > 'struct stage_info' we will need and allocate them all at once before > the 'for' loop. That's an interesting idea, but if we allocate all at once, then we'd need to be able to deallocate all at once. I'm not sure how to do that, but basically the straightforward string_list_free(conflicted_files, 1); that callers can use with the current function would no longer be valid, and it might be somewhat difficult for callers to figure out how to free the memory that was allocated.