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

Re: [PATCH 4/6] apply: refactor code to drop `line_allocated`

From
Patrick Steinhardt <ps@pks.im>
Date
Sep 17, 2024, 09:50 UTC
Message-ID
<ZulRAiILnz8WZSz4@pks.im>
In-Reply-To
<xmqqldzrmnqn.fsf@gitster.g>
On Mon, Sep 16, 2024 at 11:56:16AM -0700, Junio C Hamano wrote:
Show 12 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> 
> > Refactor the function to use memmove(3P) instead, which allows us to get
> > rid of this double bookkeeping. We call this function at most once per
> > image anyway, so this shouldn't cause any performance regressions.
> 
> Don't we call remove_first_line() as long as leading is larger than
> trailing repeatedly?  Is "at most once" accurate?
> 
> As to the correctness, I think nobody takes the address of an
> element in the line[] array and expects the address to stay valid
> across a call to remove_first_line(), so this should be safe.

Oh, you're right. I did search for a loop surrounding `image_remove_first_line()`, but somehow I completely missed the obvious `for (;;)` loop around it. No idea how I was able to miss it.

I still very much doubt that this will cause performance issues in practice (even though it's only by gut feeling), but the statement is obviously incorrect. In case the assumption ever turns out to be wrong we can likely refactor the loop to only trim contents after we have found how many lines to remove, at which point we can remove them with a single call to `strbuf_remove()`.

Patrick
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 20 in “apply: fix leaking buffer of `struct image`”
  1. 0/6 apply: fix leaking buffer of `struct image`Patrick Steinhardt, Sep 16, 2024
  2. 1/6 apply: reorder functions to move image-related things togetherPatrick Steinhardt, Sep 16, 2024
  3. 2/6 apply: rename functions operating on `struct image`Patrick Steinhardt, Sep 16, 2024
  4. 3/6 apply: introduce macro and function to init imagesPatrick Steinhardt, Sep 16, 2024
  5. 4/6 apply: refactor code to drop `line_allocated`Patrick Steinhardt, Sep 16, 2024
  6. Junio C HamanoSep 16, 2024
  7. Patrick SteinhardtSep 17, 2024
  8. Junio C HamanoSep 16, 2024
  9. 5/6 apply: rename members that track line count and allocation lengthPatrick Steinhardt, Sep 16, 2024
  10. 6/6 apply: refactor `struct image` to use a `struct strbuf`Patrick Steinhardt, Sep 16, 2024
  11. Junio C HamanoSep 16, 2024
  12. 0/6 apply: fix leaking buffer of `struct image`Patrick Steinhardt, Sep 17, 2024
  13. 1/6 apply: reorder functions to move image-related things togetherPatrick Steinhardt, Sep 17, 2024
  14. 2/6 apply: rename functions operating on `struct image`Patrick Steinhardt, Sep 17, 2024
  15. 3/6 apply: introduce macro and function to init imagesPatrick Steinhardt, Sep 17, 2024
  16. 4/6 apply: refactor code to drop `line_allocated`Patrick Steinhardt, Sep 17, 2024
  17. 5/6 apply: rename members that track line count and allocation lengthPatrick Steinhardt, Sep 17, 2024
  18. 6/6 apply: refactor `struct image` to use a `struct strbuf`Patrick Steinhardt, Sep 17, 2024
  19. Patrick SteinhardtSep 17, 2024
  20. Junio C HamanoSep 17, 2024

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.