Skip to content

Commit 19cfa0e

Browse files
chriscoolgitster
authored andcommitted
oidmap: use sha1hash() instead of static hash() function
Get rid of the static hash() function in oidmap.c which is redundant with sha1hash(). Use sha1hash() directly instead. Let's be more consistent and not use several hash functions doing nearly exactly the same thing. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c1f7f53 commit 19cfa0e

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

oidmap.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ static int oidmap_neq(const void *hashmap_cmp_fn_data,
1212
&((const struct oidmap_entry *) entry_or_key)->oid);
1313
}
1414

15-
static int hash(const struct object_id *oid)
16-
{
17-
int hash;
18-
memcpy(&hash, oid->hash, sizeof(hash));
19-
return hash;
20-
}
21-
2215
void oidmap_init(struct oidmap *map, size_t initial_size)
2316
{
2417
hashmap_init(&map->map, oidmap_neq, NULL, initial_size);
@@ -36,7 +29,7 @@ void *oidmap_get(const struct oidmap *map, const struct object_id *key)
3629
if (!map->map.cmpfn)
3730
return NULL;
3831

39-
return hashmap_get_from_hash(&map->map, hash(key), key);
32+
return hashmap_get_from_hash(&map->map, sha1hash(key->hash), key);
4033
}
4134

4235
void *oidmap_remove(struct oidmap *map, const struct object_id *key)
@@ -46,7 +39,7 @@ void *oidmap_remove(struct oidmap *map, const struct object_id *key)
4639
if (!map->map.cmpfn)
4740
oidmap_init(map, 0);
4841

49-
hashmap_entry_init(&entry, hash(key));
42+
hashmap_entry_init(&entry, sha1hash(key->hash));
5043
return hashmap_remove(&map->map, &entry, key);
5144
}
5245

@@ -57,6 +50,6 @@ void *oidmap_put(struct oidmap *map, void *entry)
5750
if (!map->map.cmpfn)
5851
oidmap_init(map, 0);
5952

60-
hashmap_entry_init(&to_put->internal_entry, hash(&to_put->oid));
53+
hashmap_entry_init(&to_put->internal_entry, sha1hash(to_put->oid.hash));
6154
return hashmap_put(&map->map, to_put);
6255
}

0 commit comments

Comments
 (0)