git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 4/6] apply: refactor code to drop `line_allocated`
Date: Tue, 17 Sep 2024 11:50:58 +0200	[thread overview]
Message-ID: <ZulRAiILnz8WZSz4@pks.im> (raw)
In-Reply-To: <xmqqldzrmnqn.fsf@gitster.g>

On Mon, Sep 16, 2024 at 11:56:16AM -0700, Junio C Hamano wrote:
> 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

  reply	other threads:[~2024-09-17  9:51 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-16  7:09 [PATCH 0/6] apply: fix leaking buffer of `struct image` Patrick Steinhardt
2024-09-16  7:10 ` [PATCH 1/6] apply: reorder functions to move image-related things together Patrick Steinhardt
2024-09-16  7:10 ` [PATCH 2/6] apply: rename functions operating on `struct image` Patrick Steinhardt
2024-09-16  7:10 ` [PATCH 3/6] apply: introduce macro and function to init images Patrick Steinhardt
2024-09-16  7:10 ` [PATCH 4/6] apply: refactor code to drop `line_allocated` Patrick Steinhardt
2024-09-16 18:56   ` Junio C Hamano
2024-09-17  9:50     ` Patrick Steinhardt [this message]
2024-09-16 21:40   ` Junio C Hamano
2024-09-16  7:10 ` [PATCH 5/6] apply: rename members that track line count and allocation length Patrick Steinhardt
2024-09-16  7:10 ` [PATCH 6/6] apply: refactor `struct image` to use a `struct strbuf` Patrick Steinhardt
2024-09-16 19:30   ` Junio C Hamano
2024-09-17 10:07 ` [PATCH v2 0/6] apply: fix leaking buffer of `struct image` Patrick Steinhardt
2024-09-17 10:07   ` [PATCH v2 1/6] apply: reorder functions to move image-related things together Patrick Steinhardt
2024-09-17 10:07   ` [PATCH v2 2/6] apply: rename functions operating on `struct image` Patrick Steinhardt
2024-09-17 10:08   ` [PATCH v2 3/6] apply: introduce macro and function to init images Patrick Steinhardt
2024-09-17 10:08   ` [PATCH v2 4/6] apply: refactor code to drop `line_allocated` Patrick Steinhardt
2024-09-17 10:08   ` [PATCH v2 5/6] apply: rename members that track line count and allocation length Patrick Steinhardt
2024-09-17 10:08   ` [PATCH v2 6/6] apply: refactor `struct image` to use a `struct strbuf` Patrick Steinhardt
2024-09-17 10:08   ` [PATCH v2 0/6] apply: fix leaking buffer of `struct image` Patrick Steinhardt
2024-09-17 20:57   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZulRAiILnz8WZSz4@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).