git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [JGIT PATCH] Support for delegating tree iterators
@ 2009-07-01 17:52 Constantine Plotnikov
  2009-07-01 22:34 ` Shawn O. Pearce
  2009-07-02 20:00 ` Robin Rosenberg
  0 siblings, 2 replies; 4+ messages in thread
From: Constantine Plotnikov @ 2009-07-01 17:52 UTC (permalink / raw
  To: git; +Cc: Constantine Plotnikov

This patch introduce some methods that simplify creation of tree
iterators that wraps other iterators and which are located in
other package. Such iterators need to efficiently access the
name component of the path of wrapped iterator and wrapped bits.
The patch also adds a method that ensuring that path buffer has
a requried capacity when the required capacity is known in advance.

Signed-off-by: Constantine Plotnikov <constantine.plotnikov@gmail.com>
---
Note that WorkingTreeIterator.parseEntry is possibly might be a good 
place to use ensurePathCapacity(...) instead or growPath(...).
  
 .../jgit/treewalk/AbstractTreeIterator.java        |   60 +++++++++++++++++++-
 1 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java
index 057250e..8f5f8c5 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java
@@ -252,8 +252,41 @@ protected AbstractTreeIterator(final AbstractTreeIterator p,
 	 *            be moved into the larger buffer.
 	 */
 	protected void growPath(final int len) {
+		setPathCapacity(path.length << 1, len);
+	}
+
+	/**
+	 * Ensure that path is capable to hold at least {@code capacity} bytes
+	 *
+	 * @param capacity
+	 *            the amount of bytes to hold
+	 * @param len
+	 *            the amount of live bytes in path buffer 
+	 */
+	protected void ensurePathCapacity(final int capacity, final int len) {
+		if(path.length >= capacity) {
+			return;
+		}
+		final byte[] o = path;
+		int current = o.length;
+		int newCapacity = current;
+		while(newCapacity < capacity && newCapacity > 0) {
+			newCapacity <<= 1;
+		}
+		setPathCapacity(newCapacity, len);
+	}
+
+	/**
+	 * Set path buffer capacity to the specified size
+	 *
+	 * @param capacity
+	 *            the new size
+	 * @param len
+	 *            the amount of bytes to copy
+	 */
+	private void setPathCapacity(int capacity, int len) {
 		final byte[] o = path;
-		final byte[] n = new byte[o.length << 1];
+		final byte[] n = new byte[capacity];
 		System.arraycopy(o, 0, n, 0, len);
 		for (AbstractTreeIterator p = this; p != null && p.path == o; p = p.parent)
 			p.path = n;
@@ -354,7 +387,12 @@ public void getEntryObjectId(final MutableObjectId out) {
 	public FileMode getEntryFileMode() {
 		return FileMode.fromBits(mode);
 	}
-
+	
+	/** @return the file mode of the current entry as bits */
+	public int getEntryFileModeBits() {
+		return mode;
+	}
+	
 	/** @return path of the current entry, as a string. */
 	public String getEntryPathString() {
 		return TreeWalk.pathOf(this);
@@ -531,4 +569,22 @@ public void skip() throws CorruptObjectException {
 	public void stopWalk() {
 		// Do nothing by default.  Most iterators do not care.
 	}
+	
+	/**
+	 * @return the length of the name component of the path for the current entry
+	 */
+	public int getNameLength() {
+		return pathLen - pathOffset;
+	}
+	
+	/**
+	 * Get the name component of the current entry path into the provided buffer.
+	 * 
+	 * @param buffer the buffer to get the name into, it is assumed that buffer can hold the name
+	 * @param offset the offset of the name in the buffer
+	 * @see #getNameLength()
+	 */
+	public void getName(byte[] buffer, int offset) {
+		System.arraycopy(path, pathOffset, buffer, offset, pathLen - pathOffset);
+	}
 }
-- 
1.6.1.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [JGIT PATCH] Support for delegating tree iterators
  2009-07-01 17:52 [JGIT PATCH] Support for delegating tree iterators Constantine Plotnikov
@ 2009-07-01 22:34 ` Shawn O. Pearce
  2009-07-01 22:41   ` Shawn O. Pearce
  2009-07-02 20:00 ` Robin Rosenberg
  1 sibling, 1 reply; 4+ messages in thread
From: Shawn O. Pearce @ 2009-07-01 22:34 UTC (permalink / raw
  To: Constantine Plotnikov; +Cc: git

Constantine Plotnikov <constantine.plotnikov@gmail.com> wrote:
> This patch introduce some methods that simplify creation of tree
> iterators that wraps other iterators and which are located in
> other package. Such iterators need to efficiently access the
> name component of the path of wrapped iterator and wrapped bits.
> The patch also adds a method that ensuring that path buffer has
> a requried capacity when the required capacity is known in advance.
> 
> Signed-off-by: Constantine Plotnikov <constantine.plotnikov@gmail.com>

Thanks, two style nits, I fixed during apply:

diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java
index 2fe756e..50befbe 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java
@@ -264,15 +264,13 @@ protected void growPath(final int len) {
 	 *            the amount of live bytes in path buffer
 	 */
 	protected void ensurePathCapacity(final int capacity, final int len) {
-		if(path.length >= capacity) {
+		if (path.length >= capacity)
 			return;
-		}
 		final byte[] o = path;
 		int current = o.length;
 		int newCapacity = current;
-		while(newCapacity < capacity && newCapacity > 0) {
+		while (newCapacity < capacity && newCapacity > 0)
 			newCapacity <<= 1;
-		}
 		setPathCapacity(newCapacity, len);
 	}
 
> ---
> Note that WorkingTreeIterator.parseEntry is possibly might be a good 
> place to use ensurePathCapacity(...) instead or growPath(...).

Yes.  I'll send a change shortly.
   
-- 
Shawn.

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [JGIT PATCH] Support for delegating tree iterators
  2009-07-01 22:34 ` Shawn O. Pearce
@ 2009-07-01 22:41   ` Shawn O. Pearce
  0 siblings, 0 replies; 4+ messages in thread
From: Shawn O. Pearce @ 2009-07-01 22:41 UTC (permalink / raw
  To: Constantine Plotnikov; +Cc: git

"Shawn O. Pearce" <spearce@spearce.org> wrote:
> Constantine Plotnikov <constantine.plotnikov@gmail.com> wrote:
> > This patch introduce some methods that simplify creation of tree
> > iterators that wraps other iterators and which are located in
> > other package. Such iterators need to efficiently access the
> > name component of the path of wrapped iterator and wrapped bits.
> > The patch also adds a method that ensuring that path buffer has
> > a requried capacity when the required capacity is known in advance.
> > 
> > Signed-off-by: Constantine Plotnikov <constantine.plotnikov@gmail.com>
> 
> Thanks, two style nits, I fixed during apply:

I also decided to squash this in, the name better matches with
TreeWalk's other like methods.  That is, the method name in TreeWalk
lacks the "Entry" prefix, but is otherwise the same name as the
name in the iterator.

diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java
index 50befbe..2116387 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java
@@ -387,7 +387,7 @@ public FileMode getEntryFileMode() {
 	}
 
 	/** @return the file mode of the current entry as bits */
-	public int getEntryFileModeBits() {
+	public int getEntryRawMode() {
 		return mode;
 	}
 
 
-- 
Shawn.

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [JGIT PATCH] Support for delegating tree iterators
  2009-07-01 17:52 [JGIT PATCH] Support for delegating tree iterators Constantine Plotnikov
  2009-07-01 22:34 ` Shawn O. Pearce
@ 2009-07-02 20:00 ` Robin Rosenberg
  1 sibling, 0 replies; 4+ messages in thread
From: Robin Rosenberg @ 2009-07-02 20:00 UTC (permalink / raw
  To: Constantine Plotnikov; +Cc: git

onsdag 01 juli 2009 19:52:52 skrev Constantine Plotnikov <constantine.plotnikov@gmail.com>:
> +	protected void ensurePathCapacity(final int capacity, final int len) {
> +		if(path.length >= capacity) {
> +			return;
> +		}
> +		final byte[] o = path;
> +		int current = o.length;
> +		int newCapacity = current;
> +		while(newCapacity < capacity && newCapacity > 0) {
> +			newCapacity <<= 1;
> +		}
> +		setPathCapacity(newCapacity, len);
> +	}

There are no JUnit tests that directly or indirectly proves this is working as only
the optimized path is taken.


> +	public int getNameLength() {
> +		return pathLen - pathOffset;
> +	}

> +	public void getName(byte[] buffer, int offset) {
> +		System.arraycopy(path, pathOffset, buffer, offset, pathLen - pathOffset);
> +	}

Never used? Not even unit test code.

> -- robin

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-07-02 20:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-01 17:52 [JGIT PATCH] Support for delegating tree iterators Constantine Plotnikov
2009-07-01 22:34 ` Shawn O. Pearce
2009-07-01 22:41   ` Shawn O. Pearce
2009-07-02 20:00 ` Robin Rosenberg

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).