diff options
author | Jonathan Nieder <jrn@google.com> | 2018-05-14 08:54:01 -0700 |
---|---|---|
committer | Jonathan Nieder <jrn@google.com> | 2018-05-14 09:02:44 -0700 |
commit | 7d9246f1636ca35f2db252581769d36c4c80e309 (patch) | |
tree | 2ca3a105f56dbdc387531c09867692733ae7cce7 | |
parent | e9e150fdd24dbeb54df614a4d47da3074c766b28 (diff) | |
download | jgit-7d9246f1636ca35f2db252581769d36c4c80e309.tar.gz jgit-7d9246f1636ca35f2db252581769d36c4c80e309.zip |
RawParseUtils#lineMap: Simplify by using null sentinel internally
Add an internal lineMapOrNull helper that returns null when the file
is binary.
This is simpler than using an exception for control flow and avoids
having to override fillInStackTrace to avoid a performance regression.
Change-Id: Ib8bb8df6a6bbd60c62cfb3b4c484a962a98b7507
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java index 66f7613e27..490cdd3cd1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java @@ -637,10 +637,8 @@ public final class RawParseUtils { * array as a single line if a '\0' is found. */ public static final IntList lineMap(final byte[] buf, int ptr, int end) { - IntList map; - try { - map = lineMapOrBinary(buf, ptr, end); - } catch (BinaryBlobException e) { + IntList map = lineMapOrNull(buf, ptr, end); + if (map == null) { map = new IntList(3); map.add(Integer.MIN_VALUE); map.add(ptr); @@ -664,6 +662,14 @@ public final class RawParseUtils { */ public static final IntList lineMapOrBinary(final byte[] buf, int ptr, int end) throws BinaryBlobException { + IntList map = lineMapOrNull(buf, ptr, end); + if (map == null) { + throw new BinaryBlobException(); + } + return map; + } + + private static @Nullable IntList lineMapOrNull(byte[] buf, int ptr, int end) { // Experimentally derived from multiple source repositories // the average number of bytes/line is 36. Its a rough guess // to initially size our map close to the target. @@ -676,15 +682,7 @@ public final class RawParseUtils { } if (buf[ptr] == '\0') { - throw new BinaryBlobException() { - - private static final long serialVersionUID = 1L; - - @Override - public Throwable fillInStackTrace() { - return this; - } - }; + return null; } foundLF = (buf[ptr] == '\n'); |