Fossil SCM

Improved hash function for the diff algorithm.

drh 2016-09-28 20:26 trunk
Commit 173cca0d7d109857801f399dc7a0bd7c5bfdd2b9
1 file changed +4 -2
+4 -2
--- src/diff.c
+++ src/diff.c
@@ -186,17 +186,19 @@
186186
while( s<k && fossil_isspace(z[s]) ){ s++; }
187187
for(h=0, x=s; x<k; x++){
188188
if( fossil_isspace(z[x]) ){
189189
++numws;
190190
}else{
191
- h = h ^ (h<<2) ^ z[x];
191
+ h += z[x];
192
+ h *= 0x9e3779b1;
192193
}
193194
}
194195
k -= numws;
195196
}else{
196197
for(h=0, x=s; x<k; x++){
197
- h = h ^ (h<<2) ^ z[x];
198
+ h += z[x];
199
+ h *= 0x9e3779b1;
198200
}
199201
}
200202
a[i].indent = s;
201203
a[i].h = h = (h<<LENGTH_MASK_SZ) | (k-s);
202204
h2 = h % nLine;
203205
--- src/diff.c
+++ src/diff.c
@@ -186,17 +186,19 @@
186 while( s<k && fossil_isspace(z[s]) ){ s++; }
187 for(h=0, x=s; x<k; x++){
188 if( fossil_isspace(z[x]) ){
189 ++numws;
190 }else{
191 h = h ^ (h<<2) ^ z[x];
 
192 }
193 }
194 k -= numws;
195 }else{
196 for(h=0, x=s; x<k; x++){
197 h = h ^ (h<<2) ^ z[x];
 
198 }
199 }
200 a[i].indent = s;
201 a[i].h = h = (h<<LENGTH_MASK_SZ) | (k-s);
202 h2 = h % nLine;
203
--- src/diff.c
+++ src/diff.c
@@ -186,17 +186,19 @@
186 while( s<k && fossil_isspace(z[s]) ){ s++; }
187 for(h=0, x=s; x<k; x++){
188 if( fossil_isspace(z[x]) ){
189 ++numws;
190 }else{
191 h += z[x];
192 h *= 0x9e3779b1;
193 }
194 }
195 k -= numws;
196 }else{
197 for(h=0, x=s; x<k; x++){
198 h += z[x];
199 h *= 0x9e3779b1;
200 }
201 }
202 a[i].indent = s;
203 a[i].h = h = (h<<LENGTH_MASK_SZ) | (k-s);
204 h2 = h % nLine;
205

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button