Skip to content

Commit 407532f

Browse files
Eric Wonggitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cf2dc1c commit 407532f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

object-file.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -567,18 +567,18 @@ static int alt_odb_usable(struct raw_object_store *o,
567567
static void read_info_alternates(struct repository *r,
568568
const char *relative_base,
569569
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,
571571
const char *relative_base, int depth, const char *normalized_objdir)
572572
{
573573
struct object_directory *ent;
574574
struct strbuf pathbuf = STRBUF_INIT;
575575
khiter_t pos;
576576

577-
if (!is_absolute_path(entry) && relative_base) {
577+
if (!is_absolute_path(entry->buf) && relative_base) {
578578
strbuf_realpath(&pathbuf, relative_base, 1);
579579
strbuf_addch(&pathbuf, '/');
580580
}
581-
strbuf_addstr(&pathbuf, entry);
581+
strbuf_addbuf(&pathbuf, entry);
582582

583583
if (strbuf_normalize_path(&pathbuf) < 0 && relative_base) {
584584
error(_("unable to normalize alternate object path: %s"),
@@ -669,7 +669,7 @@ static void link_alt_odb_entries(struct repository *r, const char *alt,
669669
alt = parse_alt_odb_entry(alt, sep, &entry);
670670
if (!entry.len)
671671
continue;
672-
link_alt_odb_entry(r, entry.buf,
672+
link_alt_odb_entry(r, &entry,
673673
relative_base, depth, objdirbuf.buf);
674674
}
675675
strbuf_release(&entry);

0 commit comments

Comments
 (0)