ObjectWalk: simplify tree traversal logic
Inline newTreeVisit into enterTree and call the new method pushTree. Use pushTree both for pushing children of the existing currVisit. Change-Id: I75ea37f48b2befb738a3e88bed40ac08f1df9a03 Signed-off-by: Matthew DeVore <matvore@gmail.com>
This commit is contained in:
parent
4cd954856e
commit
00523f38a1
|
@ -385,15 +385,15 @@ public RevObject nextObject() throws MissingObjectException,
|
||||||
obj = new RevTree(idBuffer);
|
obj = new RevTree(idBuffer);
|
||||||
obj.flags = SEEN;
|
obj.flags = SEEN;
|
||||||
objects.add(obj);
|
objects.add(obj);
|
||||||
return enterTree(obj);
|
return pushTree(obj);
|
||||||
}
|
}
|
||||||
if (!(obj instanceof RevTree))
|
if (!(obj instanceof RevTree))
|
||||||
throw new IncorrectObjectTypeException(obj, OBJ_TREE);
|
throw new IncorrectObjectTypeException(obj, OBJ_TREE);
|
||||||
obj.flags = flags = obj.flags | SEEN;
|
obj.flags = flags = obj.flags | SEEN;
|
||||||
if ((flags & UNINTERESTING) == 0)
|
if ((flags & UNINTERESTING) == 0)
|
||||||
return enterTree(obj);
|
return pushTree(obj);
|
||||||
if (boundary)
|
if (boundary)
|
||||||
return enterTree(obj);
|
return pushTree(obj);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case TYPE_GITLINK:
|
case TYPE_GITLINK:
|
||||||
|
@ -426,23 +426,17 @@ public RevObject nextObject() throws MissingObjectException,
|
||||||
o.flags = flags;
|
o.flags = flags;
|
||||||
if ((flags & UNINTERESTING) == 0 | boundary) {
|
if ((flags & UNINTERESTING) == 0 | boundary) {
|
||||||
if (o instanceof RevTree) {
|
if (o instanceof RevTree) {
|
||||||
tv = newTreeVisit(o);
|
// The previous while loop should have exhausted the stack
|
||||||
tv.parent = null;
|
// of trees.
|
||||||
currVisit = tv;
|
assert currVisit == null;
|
||||||
|
|
||||||
|
pushTree(o);
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private RevObject enterTree(RevObject obj) throws MissingObjectException,
|
|
||||||
IncorrectObjectTypeException, IOException {
|
|
||||||
TreeVisit tv = newTreeVisit(obj);
|
|
||||||
tv.parent = currVisit;
|
|
||||||
currVisit = tv;
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int findObjectId(byte[] buf, int ptr) {
|
private static int findObjectId(byte[] buf, int ptr) {
|
||||||
// Skip over the mode and name until the NUL before the ObjectId
|
// Skip over the mode and name until the NUL before the ObjectId
|
||||||
// can be located. Skip the NUL as the function returns.
|
// can be located. Skip the NUL as the function returns.
|
||||||
|
@ -768,7 +762,7 @@ private void markTreeUninteresting(RevTree tree)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private TreeVisit newTreeVisit(RevObject obj) throws LargeObjectException,
|
private RevObject pushTree(RevObject obj) throws LargeObjectException,
|
||||||
MissingObjectException, IncorrectObjectTypeException, IOException {
|
MissingObjectException, IncorrectObjectTypeException, IOException {
|
||||||
TreeVisit tv = freeVisit;
|
TreeVisit tv = freeVisit;
|
||||||
if (tv != null) {
|
if (tv != null) {
|
||||||
|
@ -782,7 +776,10 @@ private TreeVisit newTreeVisit(RevObject obj) throws LargeObjectException,
|
||||||
}
|
}
|
||||||
tv.obj = obj;
|
tv.obj = obj;
|
||||||
tv.buf = reader.open(obj, OBJ_TREE).getCachedBytes();
|
tv.buf = reader.open(obj, OBJ_TREE).getCachedBytes();
|
||||||
return tv;
|
tv.parent = currVisit;
|
||||||
|
currVisit = tv;
|
||||||
|
|
||||||
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void releaseTreeVisit(TreeVisit tv) {
|
private void releaseTreeVisit(TreeVisit tv) {
|
||||||
|
|
Loading…
Reference in New Issue