summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2015-11-27 23:21:33 -0800
committerShawn Pearce <spearce@spearce.org>2015-11-27 23:23:49 -0800
commit46e4992e9267211a55aae03b744b50edb87740fd (patch)
treee3474ef7ada85d4db5d2fd257464ba5ff8a9274d
parentbd31555ee507cd29a11060756297031354b9b0c3 (diff)
downloadjgit-46e4992e9267211a55aae03b744b50edb87740fd.tar.gz
jgit-46e4992e9267211a55aae03b744b50edb87740fd.zip
Fix performance regression in CanonicalTreeParser
Change-Id: I14046559fddb9656d890d3099010117e84cd9439
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java27
1 files changed, 12 insertions, 15 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java
index df31558ff9..c24efe20aa 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java
@@ -64,11 +64,11 @@ import org.eclipse.jgit.util.RawParseUtils;
/** Parses raw Git trees from the canonical semi-text/semi-binary format. */
public class CanonicalTreeParser extends AbstractTreeIterator {
- private static final int ATTRIBUTESLENGTH = Constants.DOT_GIT_ATTRIBUTES
- .getBytes().length;
-
private static final byte[] EMPTY = {};
+ private static final byte[] ATTRS = Constants
+ .encode(Constants.DOT_GIT_ATTRIBUTES);
+
private byte[] raw;
/** First offset within {@link #raw} of the prior entry. */
@@ -375,11 +375,9 @@ public class CanonicalTreeParser extends AbstractTreeIterator {
nextPtr = ptr + Constants.OBJECT_ID_LENGTH;
// Check if this entry is a .gitattributes file
- if (RawParseUtils.match(path, pathOffset,
- Constants.DOT_GIT_ATTRIBUTES.getBytes()) == ATTRIBUTESLENGTH)
- attributesNode = new LazyLoadingAttributesNode(
- ObjectId.fromRaw(idBuffer(), idOffset()));
-
+ if (path[pathOffset] == '.'
+ && RawParseUtils.match(path, pathOffset, ATTRS) > 0)
+ attributesNode = new LazyLoadingAttributesNode(idOffset());
}
/**
@@ -402,18 +400,18 @@ public class CanonicalTreeParser extends AbstractTreeIterator {
/**
* {@link AttributesNode} implementation that provides lazy loading
*/
- private static class LazyLoadingAttributesNode extends AttributesNode {
- final ObjectId objectId;
+ private class LazyLoadingAttributesNode extends AttributesNode {
+ private final int idOffset;
- LazyLoadingAttributesNode(ObjectId objectId) {
+ LazyLoadingAttributesNode(int idOffset) {
super(Collections.<AttributesRule> emptyList());
- this.objectId = objectId;
-
+ this.idOffset = idOffset;
}
AttributesNode load(ObjectReader reader) throws IOException {
AttributesNode r = new AttributesNode();
- ObjectLoader loader = reader.open(objectId);
+ ObjectId id = ObjectId.fromRaw(raw, idOffset);
+ ObjectLoader loader = reader.open(id);
if (loader != null) {
InputStream in = loader.openStream();
try {
@@ -425,5 +423,4 @@ public class CanonicalTreeParser extends AbstractTreeIterator {
return r.getRules().isEmpty() ? null : r;
}
}
-
}