From f635aa51f8d6d0aaa11679605cfbb4c720567baf Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Wed, 13 Dec 2017 17:10:51 -0800 Subject: [PATCH] DfsBlockCache.hasBlock0: quickly check for file in cache This can be useful for sophisticated pre-read algorithms to quickly determine if a file is likely already in cache, especially small reftables which may be smaller than a typical DFS block size. Change-Id: I7756948063b722ff650c9ba82060ff9ad554b0ba --- .../internal/storage/dfs/DfsBlockCache.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java index 03947d839..cf86fad7e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java @@ -279,6 +279,23 @@ public final class DfsBlockCache { return getStatVals(statEvict); } + /** + * Quickly check if the cache contains block 0 of the given stream. + *

+ * This can be useful for sophisticated pre-read algorithms to quickly + * determine if a file is likely already in cache, especially small + * reftables which may be smaller than a typical DFS block size. + * + * @param key + * the file to check. + * @return true if block 0 (the first block) is in the cache. + */ + public boolean hasBlock0(DfsStreamKey key) { + HashEntry e1 = table.get(slot(key, 0)); + DfsBlock v = scan(e1, key, 0); + return v != null && v.contains(key, 0); + } + private int hash(int packHash, long off) { return packHash + (int) (off >>> blockSizeShift); }