summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-02-02 14:21:27 -0800
committerShawn O. Pearce <spearce@spearce.org>2010-02-02 14:27:49 -0800
commit0e137c4d9e5c245424e78208a104fbc8b3aaee2a (patch)
tree7785536acea6aa838931ec8635d95eb93c5b89b9 /org.eclipse.jgit
parentdb54736e714e3c7e8e54b38bbf9f1c2d0026d15d (diff)
downloadjgit-0e137c4d9e5c245424e78208a104fbc8b3aaee2a.tar.gz
jgit-0e137c4d9e5c245424e78208a104fbc8b3aaee2a.zip
Micro-optimize CanonicalTreeParser next() for ObjectWalk
ObjectWalk is invoking next() for each record we consider in a tree. Rather than doing several method calls against the current parser, and testing if we are at eof() at least twice per next() invocation, do it only once and inline the logic to move the parser forward. Change-Id: If5938f5d7b3ca24f500a184c9bd2ef193015414e Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java22
1 files changed, 14 insertions, 8 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 8a202035aa..0b9dc00446 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2009, Google Inc.
+ * Copyright (C) 2008-2010, Google Inc.
* Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
* and other copyright owners as documented in the project's IP log.
*
@@ -122,7 +122,9 @@ public class CanonicalTreeParser extends AbstractTreeIterator {
raw = treeData;
prevPtr = -1;
currPtr = 0;
- if (!eof())
+ if (eof())
+ nextPtr = 0;
+ else
parseEntry();
}
@@ -159,15 +161,19 @@ public class CanonicalTreeParser extends AbstractTreeIterator {
public CanonicalTreeParser next() {
CanonicalTreeParser p = this;
for (;;) {
- p.next(1);
- if (p.eof() && p.parent != null) {
- // Parent was left pointing at the entry for us; advance
- // the parent to the next entry, possibly unwinding many
- // levels up the tree.
- //
+ if (p.nextPtr == p.raw.length) {
+ // This parser has reached EOF, return to the parent.
+ if (p.parent == null) {
+ p.currPtr = p.nextPtr;
+ return p;
+ }
p = (CanonicalTreeParser) p.parent;
continue;
}
+
+ p.prevPtr = p.currPtr;
+ p.currPtr = p.nextPtr;
+ p.parseEntry();
return p;
}
}