@matheusbsbs / matheus-bagliano / commits / 9de0834663
Fork 0

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: Davide Libenzi <davidel@xmaliserver.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed Oct 16, 2006 at 19:58 UTC 9de0834663f28bee9e6b2c4647ed6128241ed26f
1 file changed +3 -2
xdiff/xmacros.h
+3 -2
@@ -24,14 +24,15 @@
24 #define XMACROS_H
25
26
27 -#define GR_PRIME 0x9e370001UL
27
28
29 #define XDL_MIN(a, b) ((a) < (b) ? (a): (b))
30 #define XDL_MAX(a, b) ((a) > (b) ? (a): (b))
31 #define XDL_ABS(v) ((v) >= 0 ? (v): -(v))
32 #define XDL_ISDIGIT(c) ((c) >= '0' && (c) <= '9')
34 -#define XDL_HASHLONG(v, b) (((unsigned long)(v) * GR_PRIME) >> ((CHAR_BIT * sizeof(unsigned long)) - (b)))
33 +#define XDL_ADDBITS(v,b) ((v) + ((v) >> (b)))
34 +#define XDL_MASKBITS(b) ((1UL << (b)) - 1)
35 +#define XDL_HASHLONG(v,b) (XDL_ADDBITS((unsigned long)(v), b) & XDL_MASKBITS(b))
36 #define XDL_PTRFREE(p) do { if (p) { xdl_free(p); (p) = NULL; } } while (0)
37 #define XDL_LE32_PUT(p, v) \
38 do { \