aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Aniszczyk <caniszczyk@gmail.com>2011-03-18 17:28:05 -0400
committerCode Review <codereview-daemon@eclipse.org>2011-03-18 17:28:05 -0400
commit817d1a334bf158ffcb2c4248813196dfdd578215 (patch)
tree58a2d58dd62d8f5d1f4691c23de47fb5f03591cd
parentbf05108d0b1aa7253659237d6848abc72c5e185e (diff)
parent48fb404a3f155805a67bdc18c7ca22d18df03be2 (diff)
downloadjgit-817d1a334bf158ffcb2c4248813196dfdd578215.tar.gz
jgit-817d1a334bf158ffcb2c4248813196dfdd578215.zip
Merge "PackFile: Cache the packName string"
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java16
1 files changed, 11 insertions, 5 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java
index 2bf8160e28..959bf43342 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java
@@ -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;
}