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

[JGIT PATCH 2/6] Simplify RawParseUtils next and nextLF loops

From
Shawn O. Pearce <spearce@spearce.org>
Date
Dec 10, 2008, 22:05 UTC
Message-ID
<1228946751-12708-3-git-send-email-spearce@spearce.org>
In-Reply-To
<1228946751-12708-2-git-send-email-spearce@spearce.org>

We always need ptr + 1 after we read the current position, so we might as well do the much more common foo[ptr++]. A good JIT would be more likely to optimize this case over the weird else branch we had.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../src/org/spearce/jgit/util/RawParseUtils.java   |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java b/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java
index 10c2239..5a40911 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java
@@ -221,10 +221,8 @@ public static final int parseTimeZoneOffset(final byte[] b, int ptr) {
 	public static final int next(final byte[] b, int ptr, final char chrA) {
 		final int sz = b.length;
 		while (ptr < sz) {
-			if (b[ptr] == chrA)
-				return ptr + 1;
-			else
-				ptr++;
+			if (b[ptr++] == chrA)
+				return ptr;
 		}
 		return ptr;
 	}
@@ -260,11 +258,9 @@ public static final int nextLF(final byte[] b, int ptr) {
 	public static final int nextLF(final byte[] b, int ptr, final char chrA) {
 		final int sz = b.length;
 		while (ptr < sz) {
-			final byte c = b[ptr];
+			final byte c = b[ptr++];
 			if (c == chrA || c == '\n')
-				return ptr + 1;
-			else
-				ptr++;
+				return ptr;
 		}
 		return ptr;
 	}
-- 
1.6.1.rc2.299.gead4c
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 3 of 11 in “RawParseUtil improvements”
  1. 0/6 RawParseUtil improvementsShawn O. Pearce, Dec 10, 2008
  2. 1/6 Simplify RawParseUtils.nextLF invocationsShawn O. Pearce, Dec 10, 2008
  3. 2/6 Simplify RawParseUtils next and nextLF loopsShawn O. Pearce, Dec 10, 2008
  4. 3/6 Correct Javadoc of RawParseUtils next and nextLF methodsShawn O. Pearce, Dec 10, 2008
  5. 4/6 Add QuotedString class to handle C-style quoting rulesShawn O. Pearce, Dec 10, 2008
  6. 5/6 Add Bourne style quoting for TransportGitSshShawn O. Pearce, Dec 10, 2008
  7. 6/6 Add ~user friendly Bourne style quoting for TransportGitSshShawn O. Pearce, Dec 10, 2008
  8. Robin RosenbergDec 10, 2008
  9. Shawn O. PearceDec 10, 2008
  10. Robin RosenbergDec 11, 2008
  11. 4/6 Add QuotedString class to handle Git path style quoting rulesShawn O. Pearce, Dec 11, 2008

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.