mirror of
https://github.com/libgit2/libgit2.git
synced 2026-01-25 02:56:17 +00:00
Merge pull request #7186 from AHSauge/fix/optimise-git-oid-is-zero
Use git_oid_raw_cmp instead of custom loop in git_oid_is_zero
This commit is contained in:
@@ -22,6 +22,8 @@ const git_oid git_oid__empty_tree_sha1 =
|
||||
{ 0x4b, 0x82, 0x5d, 0xc6, 0x42, 0xcb, 0x6e, 0xb9, 0xa0, 0x60,
|
||||
0xe5, 0x4b, 0xf8, 0xd6, 0x92, 0x88, 0xfb, 0xee, 0x49, 0x04 });
|
||||
|
||||
static const unsigned char git_oid_zero[GIT_OID_MAX_SIZE] = {0};
|
||||
|
||||
static int oid_error_invalid(const char *msg)
|
||||
{
|
||||
git_error_set(GIT_ERROR_INVALID, "unable to parse OID - %s", msg);
|
||||
@@ -292,7 +294,7 @@ int git_oid_streq(const git_oid *oid_a, const char *str)
|
||||
int git_oid_is_zero(const git_oid *oid_a)
|
||||
{
|
||||
const unsigned char *a = oid_a->id;
|
||||
size_t size = git_oid_size(git_oid_type(oid_a)), i;
|
||||
size_t size = git_oid_size(git_oid_type(oid_a));
|
||||
|
||||
#ifdef GIT_EXPERIMENTAL_SHA256
|
||||
if (!oid_a->type)
|
||||
@@ -301,10 +303,7 @@ int git_oid_is_zero(const git_oid *oid_a)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
for (i = 0; i < size; ++i, ++a)
|
||||
if (*a != 0)
|
||||
return 0;
|
||||
return 1;
|
||||
return git_oid_raw_cmp(a, git_oid_zero, size) == 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
#ifndef GIT_DEPRECATE_HARD
|
||||
|
||||
Reference in New Issue
Block a user