Skip to content
Snippets Groups Projects
Commit 9de08346 authored by Linus Torvalds's avatar Linus Torvalds Committed by Junio C Hamano
Browse files

Fix hash function in xdiff library

Jim Mayering noticed that xdiff library took insanely long time
when comparing files with many identical lines.

This was because the hash function used in the library is broken
on 64-bit architectures and caused too many collisions.

http://thread.gmane.org/gmane.comp.version-control.git/28962/focus=28994



Acked-by: default avatarDavide Libenzi <davidel@xmaliserver.org>
Signed-off-by: default avatarJunio C Hamano <junkio@cox.net>
parent 6fe5b7ff
Branches
Tags
No related merge requests found
...@@ -24,14 +24,15 @@ ...@@ -24,14 +24,15 @@
#define XMACROS_H #define XMACROS_H
#define GR_PRIME 0x9e370001UL
#define XDL_MIN(a, b) ((a) < (b) ? (a): (b)) #define XDL_MIN(a, b) ((a) < (b) ? (a): (b))
#define XDL_MAX(a, b) ((a) > (b) ? (a): (b)) #define XDL_MAX(a, b) ((a) > (b) ? (a): (b))
#define XDL_ABS(v) ((v) >= 0 ? (v): -(v)) #define XDL_ABS(v) ((v) >= 0 ? (v): -(v))
#define XDL_ISDIGIT(c) ((c) >= '0' && (c) <= '9') #define XDL_ISDIGIT(c) ((c) >= '0' && (c) <= '9')
#define XDL_HASHLONG(v, b) (((unsigned long)(v) * GR_PRIME) >> ((CHAR_BIT * sizeof(unsigned long)) - (b))) #define XDL_ADDBITS(v,b) ((v) + ((v) >> (b)))
#define XDL_MASKBITS(b) ((1UL << (b)) - 1)
#define XDL_HASHLONG(v,b) (XDL_ADDBITS((unsigned long)(v), b) & XDL_MASKBITS(b))
#define XDL_PTRFREE(p) do { if (p) { xdl_free(p); (p) = NULL; } } while (0) #define XDL_PTRFREE(p) do { if (p) { xdl_free(p); (p) = NULL; } } while (0)
#define XDL_LE32_PUT(p, v) \ #define XDL_LE32_PUT(p, v) \
do { \ do { \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment