Browse files

Document why WindowFile's hash is *31

It doesn't really make sense on its own, but if you know about
the assumption in WindowCache.hash() it all becomes a bit more
clear to the reader.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
  • Loading branch information...
1 parent a0c15aa commit c438ba9797ac1f5b111a6a722bcdf9a1724d8f2e @spearce spearce committed with robinrosenberg Feb 11, 2009
View
3 org.spearce.jgit/src/org/spearce/jgit/lib/WindowCache.java
@@ -362,6 +362,9 @@ private static void insertLRU(final ByteWindow<?> e) {
}
private static int hash(final WindowedFile wp, final int id) {
+ // wp.hash was already "stirred up" a bit by * 31 when
+ // it was created. Its reasonable to just add here.
+ //
return ((wp.hash + id) >>> 1) % cache.length;
}
View
4 org.spearce.jgit/src/org/spearce/jgit/lib/WindowedFile.java
@@ -88,6 +88,10 @@
*/
public WindowedFile(final File file) {
fPath = file;
+
+ // Multiply by 31 here so we can more directly combine with another
+ // value in WindowCache.hash(), without doing the multiply there.
+ //
hash = System.identityHashCode(this) * 31;
length = Long.MAX_VALUE;
}

0 comments on commit c438ba9

Please sign in to comment.