diff options
author | Karsten Blees <karsten.blees@gmail.com> | 2014-07-03 00:20:20 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-07-07 22:56:24 +0200 |
commit | 039dc71a7cb824300e242f8abc0fcb19dac93641 (patch) | |
tree | 9c38bb8655e0314cfe122b7355922c2413533825 /hashmap.h | |
parent | Merge branch 'dt/refs-check-refname-component-sse' (diff) | |
download | git-039dc71a7cb824300e242f8abc0fcb19dac93641.tar.xz git-039dc71a7cb824300e242f8abc0fcb19dac93641.zip |
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>
Diffstat (limited to 'hashmap.h')
-rw-r--r-- | hashmap.h | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -13,6 +13,17 @@ extern unsigned int strihash(const char *buf); extern unsigned int memhash(const void *buf, size_t len); extern unsigned int memihash(const void *buf, size_t len); +static inline unsigned int sha1hash(const unsigned char *sha1) +{ + /* + * Equivalent to 'return *(unsigned int *)sha1;', but safe on + * platforms that don't support unaligned reads. + */ + unsigned int hash; + memcpy(&hash, sha1, sizeof(hash)); + return hash; +} + /* data structures */ struct hashmap_entry { |