[JGIT PATCH 3/9] Document why WindowFile's hash is *31
- From
Shawn O. Pearce <spearce@spearce.org>
- Date
- Feb 12, 2009, 02:36 UTC
- Message-ID
- <1234406219-19547-4-git-send-email-spearce@spearce.org>
- In-Reply-To
- <1234406219-19547-3-git-send-email-spearce@spearce.org>
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> --- .../src/org/spearce/jgit/lib/WindowCache.java | 3 +++ .../src/org/spearce/jgit/lib/WindowedFile.java | 4 ++++ 2 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/WindowCache.java b/org.spearce.jgit/src/org/spearce/jgit/lib/WindowCache.java index 600ebdf..0b9d20c 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/WindowCache.java +++ b/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; } diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/WindowedFile.java b/org.spearce.jgit/src/org/spearce/jgit/lib/WindowedFile.java index 5eb8465..db8ea88 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/WindowedFile.java +++ b/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; }
-- 1.6.2.rc0.204.gf6b427