##// END OF EJS Templates
bdiff: improve worst case behavior by 100x....
Vadim Gelfer -
r2577:fa76c5d6 default
parent child Browse files
Show More
@@ -65,7 +65,7 static inline uint32_t rol32(uint32_t wo
65 65
66 66 int splitlines(const char *a, int len, struct line **lr)
67 67 {
68 int h, i;
68 int g, h, i;
69 69 const char *p, *b = a;
70 70 struct line *l;
71 71
@@ -82,7 +82,16 int splitlines(const char *a, int len, s
82 82 /* build the line array and calculate hashes */
83 83 h = 0;
84 84 for (p = a; p < a + len; p++) {
85 h = *p + rol32(h, 7); /* a simple hash from GNU diff */
85 /*
86 * a simple hash from GNU diff, with better collision
87 * resistance from hashpjw. this slows down common
88 * case by 10%, but speeds up worst case by 100x.
89 */
90 h = *p + rol32(h, 7);
91 if ((g = h & 0xf0000000)) {
92 h ^= g >> 24;
93 h ^= g;
94 }
86 95 if (*p == '\n' || p == a + len - 1) {
87 96 l->len = p - b + 1;
88 97 l->h = h * l->len;
General Comments 0
You need to be logged in to leave comments. Login now