git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jul 1, 2009, 22:45 UTC
Message-ID
<1246488353-16867-1-git-send-email-spearce@spearce.org>

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(-)
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
Message 1 of 1 in “Avoid growing WorkingTreeIterator's path multiple times”
  1. Avoid growing WorkingTreeIterator's path multiple timesShawn O. Pearce, Jul 1, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.