threads / patch / 19997

patchAvoid growing WorkingTreeIterator's path multiple times

Subject: [JGIT PATCH] Avoid growing WorkingTreeIterator's path multiple times

## tl;dr

One message between Jul 1, 2009 and Jul 1, 2009. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Shawn O. Pearce· Jul 1, 2009, 22:45 UTC · lore

If the current path buffer isn't big enough for the current file name to be appended onto it, we can immediately grow it to the correct target size by using the new ensurePathCapacity method. This may save us from growing the buffer twice in rapid succession if the path name component is really long, and the current buffer is still the fairly small default size.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
CC: Constantine Plotnikov <constantine.plotnikov@gmail.com>
---
 .../spearce/jgit/treewalk/WorkingTreeIterator.java |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
Show changes to org.spearce.jgit/src/org/spearce/jgit/treewalk/WorkingTreeIterator.java +1 −2
diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/WorkingTreeIterator.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/WorkingTreeIterator.java
index 836b01a..d4291ea 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/WorkingTreeIterator.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/WorkingTreeIterator.java
@@ -258,8 +258,7 @@ private void parseEntry() {
 		mode = e.getMode().getBits();
 
 		final int nameLen = e.encodedNameLen;
-		while (pathOffset + nameLen > path.length)
-			growPath(pathOffset);
+		ensurePathCapacity(pathOffset + nameLen, pathOffset);
 		System.arraycopy(e.encodedName, 0, path, pathOffset, nameLen);
 		pathLen = pathOffset + nameLen;
 	}
-- 
1.6.3.3.420.gd4b46

← back to recent threads