]> source.dussan.org Git - jgit.git/commitdiff
PackFile: Cache the packName string 73/2773/1
authorShawn O. Pearce <spearce@spearce.org>
Fri, 18 Mar 2011 15:21:39 +0000 (08:21 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Fri, 18 Mar 2011 16:11:47 +0000 (09:11 -0700)
Instead of computing this on every request, compute it once and
hold onto the result. This improves performance for LocalCachedPack
which does a lot of tests against the pack name string.

Change-Id: I3803745e3a5dda7b5f0faf39aae9423e2c777e7f
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java

index 2bf8160e28d0bf4aee3aca5cd3ea63da13af9961..959bf433426472c315bcdc2bfa8cf31f695ace3f 100644 (file)
@@ -96,6 +96,8 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
 
        private final File packFile;
 
+       private volatile String packName;
+
        final int hash;
 
        private RandomAccessFile fd;
@@ -177,11 +179,15 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
 
        /** @return name extracted from {@code pack-*.pack} pattern. */
        public String getPackName() {
-               String name = getPackFile().getName();
-               if (name.startsWith("pack-"))
-                       name = name.substring("pack-".length());
-               if (name.endsWith(".pack"))
-                       name = name.substring(0, name.length() - ".pack".length());
+               String name = packName;
+               if (name == null) {
+                       name = getPackFile().getName();
+                       if (name.startsWith("pack-"))
+                               name = name.substring("pack-".length());
+                       if (name.endsWith(".pack"))
+                               name = name.substring(0, name.length() - ".pack".length());
+                       packName = name;
+               }
                return name;
        }