diff options
author | Shawn Pearce <spearce@spearce.org> | 2017-12-13 17:10:51 -0800 |
---|---|---|
committer | Shawn Pearce <spearce@spearce.org> | 2017-12-13 17:10:51 -0800 |
commit | f635aa51f8d6d0aaa11679605cfbb4c720567baf (patch) | |
tree | 30f3ca63181733d7fe392fa21e21af0a3f1ea2b4 | |
parent | c09ed93e85165e4a77f9a3b51fbd5e09555b3e7c (diff) | |
download | jgit-f635aa51f8d6d0aaa11679605cfbb4c720567baf.tar.gz jgit-f635aa51f8d6d0aaa11679605cfbb4c720567baf.zip |
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
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java | 17 |
1 files changed, 17 insertions, 0 deletions
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 03947d8395..cf86fad7e4 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. + * <p> + * 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); } |