]> git.ipfire.org Git - thirdparty/git.git/commit
apply: refactor code to drop `line_allocated`
authorPatrick Steinhardt <ps@pks.im>
Tue, 17 Sep 2024 10:08:03 +0000 (12:08 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 17 Sep 2024 20:53:30 +0000 (13:53 -0700)
commit6eff8b8f406f53ad3301263300016813f1d73c63
treec29e6e04bba18e28e9f4672a3f3031f4a2a3643d
parent7db28d0133a8b828c8d7a829b587711acf81cddc
apply: refactor code to drop `line_allocated`

The `struct image` has two members `line` and `line_allocated`. The
former member is the one that should be used throughout the code,
whereas the latter one is used to track whether the lines have been
allocated or not.

In practice, the array of lines is always allocated. The reason why we
have `line_allocated` is that `remove_first_line()` will advance the
array pointer to drop the first entry, and thus it points into the array
instead of to the array header.

Refactor the function to use memmove(3P) instead, which allows us to get
rid of this double bookkeeping. This is less efficient, but I doubt that
this matters much in practice. If this judgement call is found to be
wrong at a later point in time we can likely refactor the surrounding
loop such that we first calculate the number of leading context lines to
remove and then remove them in a single call to memmove(3P).

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
apply.c