Re: [PATCH 3/4] grep: simplify color setup
- From
Jeff King <peff@peff.net>
- Date
- Nov 21, 2020, 20:23 UTC
- Message-ID
- <20201121202310.GA972561@coredump.intra.peff.net>
- In-Reply-To
- <d6e43bc540bc682bb46d54e579a7101d0d2c462d.1605972564.git.martin.agren@gmail.com>
On Sat, Nov 21, 2020 at 07:31:09PM +0100, Martin Ågren wrote:
Show 10 quoted lines
> 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 <martin.agren@gmail.com> > --- > 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