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

Re: [PATCH 1/5] trailer: use singly-linked list, not doubly

From
Jeff King <peff@peff.net>
Date
Oct 12, 2016, 17:26 UTC
Message-ID
<20161012172605.tudfyg657cn4e5sj@sigill.intra.peff.net>
In-Reply-To
<CAP8UFD03sOgVVb5-VEgHxHaXBBUPJ9UTB0=Y=th8YnUCk+Aa4Q@mail.gmail.com>
On Wed, Oct 12, 2016 at 05:38:14PM +0200, Christian Couder wrote:
Show 12 quoted lines
> On Wed, Oct 12, 2016 at 3:23 AM, Jonathan Tan <jonathantanmy@google.com> wrote:
> > Use singly-linked lists (instead of doubly-linked lists) in trailer to
> > keep track of arguments (whether implicit from configuration or explicit
> > from the command line) and trailer items.
> >
> > This change significantly reduces the code length and simplifies the code.
> 
> It's true that the code can be simplified a lot by using a
> singly-linked list, but if we already had and used some generic
> functions or macros to handle doubly-linked list, I doubt there would
> be a significant simplification (as the generic code could not be
> deleted in this case).

We didn't have such generic macros when you wrote the trailer code originally, but we do now, in list.h (they come from the kernel's doubly-linked list implementation). I used them recently in a series and found them pretty pleasant and complete.

Maybe it's worth trying the conversion here to see if it simplifies the code.

Show 13 quoted lines
> > There are now fewer pointers to be manipulated, but most trailer
> > manipulations now require seeking from beginning to end, so there might
> > be a slight net decrease in performance; however the number of trailers
> > is usually small (10 to 15 at the most) so this should not cause a big
> > impact.
> 
> By default we append new trailers at the end of the trailer list, so a
> singly-linked list is theoretically not well suited at all for
> handling trailer lists.
> 
> You say that at most there is a small number of trailers, and that may
> be true indeed for the Linux kernel and most projects these days, but
> I am not sure it is a good assumption to make in general.

I agree. As somebody who has fixed quite a number of accidentally quadratic cases in the number of refs, width of the commit graph, etc, over the years, these things have a way of creeping up or finding pathological cases.

You _can_ append to a singly linked list in O(1) if you keep a tail pointer, but I think using list.h would be even nicer.

-Peff
Previous: Christian CouderNext: Jonathan Tan
Message 5 of 48 in “allow non-trailers and multiple-line trailers”
  1. 0/5 allow non-trailers and multiple-line trailersJonathan Tan, Oct 12, 2016
  2. 1/5 trailer: use singly-linked list, not doublyJonathan Tan, Oct 12, 2016
  3. Junio C HamanoOct 12, 2016
  4. Christian CouderOct 12, 2016
  5. Jeff KingOct 12, 2016
  6. 5/5 trailer: support values folded to multiple linesJonathan Tan, Oct 12, 2016
  7. Junio C HamanoOct 12, 2016
  8. 2/5 trailer: streamline trailer item create and addJonathan Tan, Oct 12, 2016
  9. 4/5 trailer: allow non-trailers in trailer blockJonathan Tan, Oct 12, 2016
  10. 3/5 trailer: make args have their own structJonathan Tan, Oct 12, 2016
  11. 0/6 allow non-trailers and multiple-line trailersJonathan Tan, Oct 12, 2016
  12. 1/6 trailer: improve const correctnessJonathan Tan, Oct 12, 2016
  13. 2/6 trailer: use list.h for doubly-linked listJonathan Tan, Oct 12, 2016
  14. Junio C HamanoOct 14, 2016
  15. Jakub NarębskiOct 14, 2016
  16. 3/6 trailer: streamline trailer item create and addJonathan Tan, Oct 12, 2016
  17. 4/6 trailer: make args have their own structJonathan Tan, Oct 12, 2016
  18. 5/6 trailer: allow non-trailers in trailer blockJonathan Tan, Oct 12, 2016
  19. 6/6 trailer: support values folded to multiple linesJonathan Tan, Oct 12, 2016
  20. 0/6 allow non-trailers and multiple-line trailersJonathan Tan, Oct 14, 2016
  21. 1/6 trailer: improve const correctnessJonathan Tan, Oct 14, 2016
  22. Stefan BellerOct 17, 2016
  23. 2/6 trailer: use list.h for doubly-linked listJonathan Tan, Oct 14, 2016
  24. 3/6 trailer: streamline trailer item create and addJonathan Tan, Oct 14, 2016
  25. Stefan BellerOct 17, 2016
  26. 5/6 trailer: allow non-trailers in trailer blockJonathan Tan, Oct 14, 2016
  27. Stefan BellerOct 18, 2016
  28. Junio C HamanoOct 18, 2016
  29. Jonathan TanOct 18, 2016
  30. Junio C HamanoOct 18, 2016
  31. Jonathan TanOct 19, 2016
  32. Junio C HamanoOct 19, 2016
  33. 6/6 trailer: support values folded to multiple linesJonathan Tan, Oct 14, 2016
  34. Stefan BellerOct 18, 2016
  35. 4/6 trailer: make args have their own structJonathan Tan, Oct 14, 2016
  36. Stefan BellerOct 17, 2016
  37. Junio C HamanoOct 18, 2016
  38. 0/8 allow non-trailers and multiple-line trailersJonathan Tan, Oct 21, 2016
  39. 1/8 trailer: improve const correctnessJonathan Tan, Oct 21, 2016
  40. 5/8 trailer: clarify failure modes in parse_trailerJonathan Tan, Oct 21, 2016
  41. 4/8 trailer: make args have their own structJonathan Tan, Oct 21, 2016
  42. 7/8 trailer: forbid leading whitespace in trailersJonathan Tan, Oct 21, 2016
  43. 6/8 trailer: allow non-trailers in trailer blockJonathan Tan, Oct 21, 2016
  44. 8/8 trailer: support values folded to multiple linesJonathan Tan, Oct 21, 2016
  45. 3/8 trailer: streamline trailer item create and addJonathan Tan, Oct 21, 2016
  46. 2/8 trailer: use list.h for doubly-linked listJonathan Tan, Oct 21, 2016
  47. Junio C HamanoOct 21, 2016
  48. Stefan BellerOct 22, 2016

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.