From 8f9c4ee41d043d97b4dd0944c4ee2e4d387b5d3c Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Fri, 6 Apr 2012 00:26:06 +0200 Subject: [PATCH] Cleanup possiblyFilteredInputStream() in WorkingTreeIterator Use early return instead of nested if/else Change-Id: I3b5048f9f5cfdfd01f916af550722532db3f9bb3 --- .../jgit/treewalk/WorkingTreeIterator.java | 55 +++++++++---------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java index 955d7d8575..027101bf88 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java @@ -335,39 +335,36 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { private InputStream possiblyFilteredInputStream(final Entry e, final InputStream is, final long len) throws IOException { - InputStream filteredIs; if (!mightNeedCleaning()) { - filteredIs = is; canonLen = len; - } else { - if (len <= MAXIMUM_FILE_SIZE_TO_READ_FULLY) { - ByteBuffer rawbuf = IO.readWholeStream(is, (int) len); - byte[] raw = rawbuf.array(); - int n = rawbuf.limit(); - if (!isBinary(raw, n)) { - rawbuf = filterClean(raw, n); - raw = rawbuf.array(); - n = rawbuf.limit(); - } - filteredIs = new ByteArrayInputStream(raw, 0, n); - canonLen = n; - } else { - if (isBinary(e)) { - filteredIs = is; - canonLen = len; - } else { - final InputStream lenIs = filterClean(e - .openInputStream()); - try { - canonLen = computeLength(lenIs); - } finally { - safeClose(lenIs); - } - filteredIs = filterClean(is); - } + return is; + } + + if (len <= MAXIMUM_FILE_SIZE_TO_READ_FULLY) { + ByteBuffer rawbuf = IO.readWholeStream(is, (int) len); + byte[] raw = rawbuf.array(); + int n = rawbuf.limit(); + if (!isBinary(raw, n)) { + rawbuf = filterClean(raw, n); + raw = rawbuf.array(); + n = rawbuf.limit(); } + canonLen = n; + return new ByteArrayInputStream(raw, 0, n); + } + + if (isBinary(e)) { + canonLen = len; + return is; + } + + final InputStream lenIs = filterClean(e.openInputStream()); + try { + canonLen = computeLength(lenIs); + } finally { + safeClose(lenIs); } - return filteredIs; + return filterClean(is); } private static void safeClose(final InputStream in) { -- 2.39.5