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-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 5C7491F66F for ; Sat, 21 Nov 2020 20:25:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728449AbgKUUXM (ORCPT ); Sat, 21 Nov 2020 15:23:12 -0500 Received: from cloud.peff.net ([104.130.231.41]:37560 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728402AbgKUUXM (ORCPT ); Sat, 21 Nov 2020 15:23:12 -0500 Received: (qmail 12603 invoked by uid 109); 21 Nov 2020 20:23:12 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Sat, 21 Nov 2020 20:23:12 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 19791 invoked by uid 111); 21 Nov 2020 20:23:10 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Sat, 21 Nov 2020 15:23:10 -0500 Authentication-Results: peff.net; auth=none Date: Sat, 21 Nov 2020 15:23:10 -0500 From: Jeff King To: Martin =?utf-8?B?w4VncmVu?= Cc: git@vger.kernel.org, Junio C Hamano , Emily Shaffer Subject: Re: [PATCH 3/4] grep: simplify color setup Message-ID: <20201121202310.GA972561@coredump.intra.peff.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Sat, Nov 21, 2020 at 07:31:09PM +0100, Martin Ågren wrote: > The previous commit left us with only one user of the one-line wrapper > `color_set()`. We could inline it, but note how we're `xsnprintf()`-ing > all the entries in one array into another array of the same type. We > might as well just `memcpy()` everything into place. > > Signed-off-by: Martin Ågren > --- > Cc-ing Peff, who initially introduced this helper. After having inlined > the function into the for loop, it seemed better to just copy the whole > array. Happy to hear arguments against. No, this is way better than the existing code. I introduced it to get away from strcpy(), but this is better still. But... > Come to think of it, I suppose we could copy the whole struct and not > just the color array. Hmmm... Yes, this seems even better. If our goal is just to start our new grep_opt the same as grep_defaults, then a single-line struct copy (whether through assignment or memcpy) is even clearer and more maintainable. -Peff