git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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
Previous: Martin ÅgrenNext: Martin Ågren
Message 5 of 26 in “grep: retire `init_grep_defaults()`”
  1. 0/4 grep: retire `init_grep_defaults()`Martin Ågren, Nov 21, 2020
  2. 1/4 grep: don't set up a "default" repo for grepMartin Ågren, Nov 21, 2020
  3. 2/4 grep: use designated initializers for `grep_defaults`Martin Ågren, Nov 21, 2020
  4. 3/4 grep: simplify color setupMartin Ågren, Nov 21, 2020
  5. Jeff KingNov 21, 2020
  6. Martin ÅgrenNov 21, 2020
  7. Junio C HamanoNov 21, 2020
  8. Jeff KingNov 24, 2020
  9. 4/4 MyFirstObjectWalk: drop `init_walken_defaults()`Martin Ågren, Nov 21, 2020
  10. Johannes SchindelinNov 23, 2020
  11. 0/4 grep: simplify "grep defaults" handlingMartin Ågren, Nov 24, 2020
  12. 1/4 grep: don't set up a "default" repo for grepMartin Ågren, Nov 24, 2020
  13. 2/4 grep: use designated initializers for `grep_defaults`Martin Ågren, Nov 24, 2020
  14. 3/4 grep: copy struct in one fell swoopMartin Ågren, Nov 24, 2020
  15. Junio C HamanoNov 24, 2020
  16. Martin ÅgrenNov 25, 2020
  17. Junio C HamanoNov 25, 2020
  18. Martin ÅgrenNov 26, 2020
  19. 4/4 MyFirstObjectWalk: drop `init_walken_defaults()`Martin Ågren, Nov 24, 2020
  20. Ævar Arnfjörð BjarmasonNov 25, 2020
  21. 0/4 grep: simplify "grep defaults" handlingMartin Ågren, Nov 29, 2020
  22. 1/4 grep: don't set up a "default" repo for grepMartin Ågren, Nov 29, 2020
  23. 2/4 grep: use designated initializers for `grep_defaults`Martin Ågren, Nov 29, 2020
  24. 3/4 grep: copy struct in one fell swoopMartin Ågren, Nov 29, 2020
  25. 4/4 MyFirstObjectWalk: drop `init_walken_defaults()`Martin Ågren, Nov 29, 2020
  26. Junio C HamanoDec 1, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.