Commit 87cb6dc
ref-filter: simplify lstrip_ref_components() memory handling
We're walking forward in the string, skipping path components from
left-to-right. So when we've stripped as much as we want, the pointer we
have is a complete NUL-terminated string and we can just return it
(after duplicating it, of course). So there is no need for a temporary
allocated string.
But we do make an extra temporary copy due to f0062d3 (ref-filter:
free item->value and item->value->s, 2018-10-18). This is probably from
cargo-culting the technique used in rstrip_ref_components(), which
_does_ need a separate string (since it is stripping from the end and
ties off the temporary string with a NUL).
Let's drop the extra allocation. This is slightly more efficient, but
more importantly makes the code much simpler.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>1 parent 5ec4c22 commit 87cb6dc
1 file changed
Lines changed: 2 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2196 | 2196 | | |
2197 | 2197 | | |
2198 | 2198 | | |
2199 | | - | |
2200 | | - | |
2201 | 2199 | | |
2202 | 2200 | | |
2203 | | - | |
| 2201 | + | |
2204 | 2202 | | |
2205 | | - | |
2206 | 2203 | | |
2207 | 2204 | | |
2208 | 2205 | | |
2209 | 2206 | | |
2210 | 2207 | | |
2211 | 2208 | | |
2212 | 2209 | | |
2213 | | - | |
2214 | | - | |
2215 | | - | |
| 2210 | + | |
2216 | 2211 | | |
2217 | 2212 | | |
2218 | 2213 | | |
| |||
0 commit comments