Skip to content

Commit e43d2dc

Browse files
peffgitster
authored andcommitted
more oideq/hasheq conversions
We added faster equality-comparison functions for hashes in 14438c4 (introduce hasheq() and oideq(), 2018-08-28). A few topics were in-flight at the time, and can now be converted. This covers all spots found by "make coccicheck" in master (the coccicheck results were tweaked by hand for style). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fe8321e commit e43d2dc

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

builtin/checkout.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,8 @@ static int skip_merge_working_tree(const struct checkout_opts *opts,
497497
* We must do the merge if we are actually moving to a new commit.
498498
*/
499499
if (!old_branch_info->commit || !new_branch_info->commit ||
500-
oidcmp(&old_branch_info->commit->object.oid, &new_branch_info->commit->object.oid))
500+
!oideq(&old_branch_info->commit->object.oid,
501+
&new_branch_info->commit->object.oid))
501502
return 0;
502503

503504
/*

cache-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ static void verify_one(struct index_state *istate,
781781
strbuf_add(&tree_buf, oid->hash, the_hash_algo->rawsz);
782782
}
783783
hash_object_file(tree_buf.buf, tree_buf.len, tree_type, &new_oid);
784-
if (oidcmp(&new_oid, &it->oid))
784+
if (!oideq(&new_oid, &it->oid))
785785
BUG("cache-tree for path %.*s does not match. "
786786
"Expected %s got %s", len, path->buf,
787787
oid_to_hex(&new_oid), oid_to_hex(&it->oid));

commit-reach.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ struct contains_stack {
426426
static int in_commit_list(const struct commit_list *want, struct commit *c)
427427
{
428428
for (; want; want = want->next)
429-
if (!oidcmp(&want->item->object.oid, &c->object.oid))
429+
if (oideq(&want->item->object.oid, &c->object.oid))
430430
return 1;
431431
return 0;
432432
}

midx.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ static int nth_midxed_pack_entry(struct multi_pack_index *m, struct pack_entry *
285285
struct object_id oid;
286286
nth_midxed_object_oid(&oid, m, pos);
287287
for (i = 0; i < p->num_bad_objects; i++)
288-
if (!hashcmp(oid.hash,
289-
p->bad_object_sha1 + the_hash_algo->rawsz * i))
288+
if (hasheq(oid.hash,
289+
p->bad_object_sha1 + the_hash_algo->rawsz * i))
290290
return 0;
291291
}
292292

@@ -583,8 +583,8 @@ static struct pack_midx_entry *get_sorted_entries(struct multi_pack_index *m,
583583
* Take only the first duplicate.
584584
*/
585585
for (cur_object = 0; cur_object < nr_fanout; cur_object++) {
586-
if (cur_object && !oidcmp(&entries_by_fanout[cur_object - 1].oid,
587-
&entries_by_fanout[cur_object].oid))
586+
if (cur_object && oideq(&entries_by_fanout[cur_object - 1].oid,
587+
&entries_by_fanout[cur_object].oid))
588588
continue;
589589

590590
ALLOC_GROW(deduplicated_entries, *nr_objects + 1, alloc_objects);

0 commit comments

Comments
 (0)