git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* [PATCH] bisect: use oid_to_hex_r() instead of memcpy()+oid_to_hex()
@ 2020-07-26 17:41 René Scharfe
  2020-07-26 19:02 ` brian m. carlson
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2020-07-26 17:41 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Matheus Tavares

Write the hexadecimal object ID directly into the destination buffer
using oid_to_hex_r() instead of writing it into a static buffer first
using oid_to_hex() and then copying it from there using memcpy().
This is shorter, simpler and a bit more efficient.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 bisect.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bisect.c b/bisect.c
index d5e830410f..be3ff1e962 100644
--- a/bisect.c
+++ b/bisect.c
@@ -709,7 +709,7 @@ static enum bisect_error bisect_checkout(const struct object_id *bisect_rev, int
 	char bisect_rev_hex[GIT_MAX_HEXSZ + 1];
 	enum bisect_error res = BISECT_OK;

-	memcpy(bisect_rev_hex, oid_to_hex(bisect_rev), the_hash_algo->hexsz + 1);
+	oid_to_hex_r(bisect_rev_hex, bisect_rev);
 	update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR);

 	argv_checkout[2] = bisect_rev_hex;
--
2.27.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] bisect: use oid_to_hex_r() instead of memcpy()+oid_to_hex()
  2020-07-26 17:41 [PATCH] bisect: use oid_to_hex_r() instead of memcpy()+oid_to_hex() René Scharfe
@ 2020-07-26 19:02 ` brian m. carlson
  0 siblings, 0 replies; 2+ messages in thread
From: brian m. carlson @ 2020-07-26 19:02 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git Mailing List, Matheus Tavares

[-- Attachment #1: Type: text/plain, Size: 1179 bytes --]

On 2020-07-26 at 17:41:12, René Scharfe wrote:
> Write the hexadecimal object ID directly into the destination buffer
> using oid_to_hex_r() instead of writing it into a static buffer first
> using oid_to_hex() and then copying it from there using memcpy().
> This is shorter, simpler and a bit more efficient.
> 
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
>  bisect.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/bisect.c b/bisect.c
> index d5e830410f..be3ff1e962 100644
> --- a/bisect.c
> +++ b/bisect.c
> @@ -709,7 +709,7 @@ static enum bisect_error bisect_checkout(const struct object_id *bisect_rev, int
>  	char bisect_rev_hex[GIT_MAX_HEXSZ + 1];
>  	enum bisect_error res = BISECT_OK;
> 
> -	memcpy(bisect_rev_hex, oid_to_hex(bisect_rev), the_hash_algo->hexsz + 1);
> +	oid_to_hex_r(bisect_rev_hex, bisect_rev);
>  	update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
> 
>  	argv_checkout[2] = bisect_rev_hex;

Yeah, this seems better in pretty much every way, and as a nice perk we
lose an explicit dependency on the_hash_algo.
-- 
brian m. carlson: Houston, Texas, US

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-07-26 19:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-26 17:41 [PATCH] bisect: use oid_to_hex_r() instead of memcpy()+oid_to_hex() René Scharfe
2020-07-26 19:02 ` brian m. carlson

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.version-control.git
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.version-control.git
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git