From 4a7e27e95797c0a094f8ee300a260777ddd7eec9 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 28 Aug 2018 17:22:40 -0400 Subject: convert "oidcmp() == 0" to oideq() Using the more restrictive oideq() should, in the long run, give the compiler more opportunities to optimize these callsites. For now, this conversion should be a complete noop with respect to the generated code. The result is also perhaps a little more readable, as it avoids the "zero is equal" idiom. Since it's so prevalent in C, I think seasoned programmers tend not to even notice it anymore, but it can sometimes make for awkward double negations (e.g., we can drop a few !!oidcmp() instances here). This patch was generated almost entirely by the included coccinelle patch. This mechanical conversion should be completely safe, because we check explicitly for cases where oidcmp() is compared to 0, which is what oideq() is doing under the hood. Note that we don't have to catch "!oidcmp()" separately; coccinelle's standard isomorphisms make sure the two are treated equivalently. I say "almost" because I did hand-edit the coccinelle output to fix up a few style violations (it mostly keeps the original formatting, but sometimes unwraps long lines). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- pack-write.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pack-write.c') diff --git a/pack-write.c b/pack-write.c index a9d46bc03f..7d14716c40 100644 --- a/pack-write.c +++ b/pack-write.c @@ -124,7 +124,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec } hashwrite(f, obj->oid.hash, the_hash_algo->rawsz); if ((opts->flags & WRITE_IDX_STRICT) && - (i && !oidcmp(&list[-2]->oid, &obj->oid))) + (i && oideq(&list[-2]->oid, &obj->oid))) die("The same object %s appears twice in the pack", oid_to_hex(&obj->oid)); } -- cgit v1.2.3 From 67947c34ae8f666e72b9406a38984fe8386f5e50 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 28 Aug 2018 17:22:52 -0400 Subject: convert "hashcmp() != 0" to "!hasheq()" This rounds out the previous three patches, covering the inequality logic for the "hash" variant of the functions. As with the previous three, the accompanying code changes are the mechanical result of applying the coccinelle patch; see those patches for more discussion. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- pack-write.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pack-write.c') diff --git a/pack-write.c b/pack-write.c index 7d14716c40..29d17a9bec 100644 --- a/pack-write.c +++ b/pack-write.c @@ -260,7 +260,7 @@ void fixup_pack_header_footer(int pack_fd, if (partial_pack_offset == 0) { unsigned char hash[GIT_MAX_RAWSZ]; the_hash_algo->final_fn(hash, &old_hash_ctx); - if (hashcmp(hash, partial_pack_hash) != 0) + if (!hasheq(hash, partial_pack_hash)) die("Unexpected checksum for %s " "(disk corruption?)", pack_name); /* -- cgit v1.2.3