]> git.ipfire.org Git - thirdparty/git.git/commit
sparse-index: use strbuf in path_found()
authorDerrick Stolee <stolee@gmail.com>
Fri, 28 Jun 2024 12:43:23 +0000 (12:43 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 28 Jun 2024 19:32:11 +0000 (12:32 -0700)
commit23dd6f8bcc11fc4a468f0863b64f3ebe27a173cd
treee3caf08d1411312dd44f300e5b21c54ffced51e2
parentb746a85d9a0d2384d3219b3b53593ccb880f3124
sparse-index: use strbuf in path_found()

The path_found() method previously reused strings from the cache entries
the calling methods were using. This prevents string manipulation in
place and causes some odd reallocation before the final lstat() call in
the method.

Refactor the method to use strbufs and copy the path into the strbuf,
but also only the parent directory and not the whole path. This looks
like extra copying when assigning the path to the strbuf, but we save an
allocation by dropping the 'tmp' string, and we are "reusing" the copy
from 'tmp' to put the data in the strbuf.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sparse-index.c