avoid strlen via strbuf_addstr in link_alt_odb_entry
We can save a few milliseconds (across 100K odbs) by using strbuf_addbuf() instead of strbuf_addstr() by passing `entry' as a strbuf pointer rather than a "const char *". Signed-off-by: Eric Wong <e@80x24.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eric Wong committed
Jul 7, 2021 at 23:10 UTC
407532f82d3fdfd18d4ec276ddeb359e7c724aa6
1 file changed
+4
-4
object-file.c
+4
-4
@@ -567,18 +567,18 @@ static int alt_odb_usable(struct raw_object_store *o,
567
static void read_info_alternates(struct repository *r,
568
const char *relative_base,
569
int depth);
570
-static int link_alt_odb_entry(struct repository *r, const char *entry,
570
+static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
571
const char *relative_base, int depth, const char *normalized_objdir)
572
{
573
struct object_directory *ent;
574
struct strbuf pathbuf = STRBUF_INIT;
575
khiter_t pos;
576
577
- if (!is_absolute_path(entry) && relative_base) {
577
+ if (!is_absolute_path(entry->buf) && relative_base) {
578
strbuf_realpath(&pathbuf, relative_base, 1);
579
strbuf_addch(&pathbuf, '/');
580
}
581
- strbuf_addstr(&pathbuf, entry);
581
+ strbuf_addbuf(&pathbuf, entry);
582
583
if (strbuf_normalize_path(&pathbuf) < 0 && relative_base) {
584
error(_("unable to normalize alternate object path: %s"),
@@ -669,7 +669,7 @@ static void link_alt_odb_entries(struct repository *r, const char *alt,
669
alt = parse_alt_odb_entry(alt, sep, &entry);
670
if (!entry.len)
671
continue;
672
- link_alt_odb_entry(r, entry.buf,
672
+ link_alt_odb_entry(r, &entry,
673
relative_base, depth, objdirbuf.buf);
674
}
675
strbuf_release(&entry);