mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
hashmap: factor out getting a hash code from a SHA1
Copying the first bytes of a SHA1 is duplicated in six places, however, the implications (the actual value would depend on the endianness of the platform) is documented only once. Add a properly documented API for this. Signed-off-by: Karsten Blees <blees@dcon.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
6f92e5ff3c
commit
039dc71a7c
13
object.c
13
object.c
@@ -50,18 +50,7 @@ int type_from_string(const char *str)
|
||||
*/
|
||||
static unsigned int hash_obj(const unsigned char *sha1, unsigned int n)
|
||||
{
|
||||
unsigned int hash;
|
||||
|
||||
/*
|
||||
* Since the sha1 is essentially random, we just take the
|
||||
* required number of bits directly from the first
|
||||
* sizeof(unsigned int) bytes of sha1. First we have to copy
|
||||
* the bytes into a properly aligned integer. If we cared
|
||||
* about getting consistent results across architectures, we
|
||||
* would have to call ntohl() here, too.
|
||||
*/
|
||||
memcpy(&hash, sha1, sizeof(unsigned int));
|
||||
return hash & (n - 1);
|
||||
return sha1hash(sha1) & (n - 1);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user