diff mbox series

[v3,2/5] avoid strlen via strbuf_addstr in link_alt_odb_entry

Message ID 20210707231019.14738-3-e@80x24.org (mailing list archive)
State Accepted
Commit 407532f82d3fdfd18d4ec276ddeb359e7c724aa6
Headers show
Series [v3,1/5] speed up alt_odb_usable() with many alternates | expand

Commit Message

Eric Wong July 7, 2021, 11:10 p.m. UTC
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>
---
 object-file.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Junio C Hamano July 8, 2021, 4:57 a.m. UTC | #1
Eric Wong <e@80x24.org> writes:

> 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 *".

OK; trivially corect ;-)

>
> Signed-off-by: Eric Wong <e@80x24.org>
> ---
>  object-file.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/object-file.c b/object-file.c
> index a13f49b192..2dd70ddf3a 100644
> --- a/object-file.c
> +++ b/object-file.c
> @@ -567,18 +567,18 @@ static int alt_odb_usable(struct raw_object_store *o,
>  static void read_info_alternates(struct repository *r,
>  				 const char *relative_base,
>  				 int depth);
> -static int link_alt_odb_entry(struct repository *r, const char *entry,
> +static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
>  	const char *relative_base, int depth, const char *normalized_objdir)
>  {
>  	struct object_directory *ent;
>  	struct strbuf pathbuf = STRBUF_INIT;
>  	khiter_t pos;
>  
> -	if (!is_absolute_path(entry) && relative_base) {
> +	if (!is_absolute_path(entry->buf) && relative_base) {
>  		strbuf_realpath(&pathbuf, relative_base, 1);
>  		strbuf_addch(&pathbuf, '/');
>  	}
> -	strbuf_addstr(&pathbuf, entry);
> +	strbuf_addbuf(&pathbuf, entry);
>  
>  	if (strbuf_normalize_path(&pathbuf) < 0 && relative_base) {
>  		error(_("unable to normalize alternate object path: %s"),
> @@ -669,7 +669,7 @@ static void link_alt_odb_entries(struct repository *r, const char *alt,
>  		alt = parse_alt_odb_entry(alt, sep, &entry);
>  		if (!entry.len)
>  			continue;
> -		link_alt_odb_entry(r, entry.buf,
> +		link_alt_odb_entry(r, &entry,
>  				   relative_base, depth, objdirbuf.buf);
>  	}
>  	strbuf_release(&entry);
diff mbox series

Patch

diff --git a/object-file.c b/object-file.c
index a13f49b192..2dd70ddf3a 100644
--- a/object-file.c
+++ b/object-file.c
@@ -567,18 +567,18 @@  static int alt_odb_usable(struct raw_object_store *o,
 static void read_info_alternates(struct repository *r,
 				 const char *relative_base,
 				 int depth);
-static int link_alt_odb_entry(struct repository *r, const char *entry,
+static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
 	const char *relative_base, int depth, const char *normalized_objdir)
 {
 	struct object_directory *ent;
 	struct strbuf pathbuf = STRBUF_INIT;
 	khiter_t pos;
 
-	if (!is_absolute_path(entry) && relative_base) {
+	if (!is_absolute_path(entry->buf) && relative_base) {
 		strbuf_realpath(&pathbuf, relative_base, 1);
 		strbuf_addch(&pathbuf, '/');
 	}
-	strbuf_addstr(&pathbuf, entry);
+	strbuf_addbuf(&pathbuf, entry);
 
 	if (strbuf_normalize_path(&pathbuf) < 0 && relative_base) {
 		error(_("unable to normalize alternate object path: %s"),
@@ -669,7 +669,7 @@  static void link_alt_odb_entries(struct repository *r, const char *alt,
 		alt = parse_alt_odb_entry(alt, sep, &entry);
 		if (!entry.len)
 			continue;
-		link_alt_odb_entry(r, entry.buf,
+		link_alt_odb_entry(r, &entry,
 				   relative_base, depth, objdirbuf.buf);
 	}
 	strbuf_release(&entry);