From 3d8649ddef2874aeea7e3e83b47e5fd4867c5cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C5=A1a=20=C5=BDivkov?= Date: Fri, 27 Sep 2019 15:58:10 +0200 Subject: [PATCH] Do not rely on ArrayIndexOutOfBoundsException to detect end of input In the Config#StringReader we relied on ArrayIndexOutOfBoundsException to detect the end of the input. Creation of exception with (deep) stack trace can significantly degrade performance in case when we read thousands of config files, like in the case when Gerrit reads all external ids from the NoteDb. Use the buf.length to detect the end of the input. Change-Id: I12266f25751373a870ce3fa623cf2a95d882d521 --- org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java index b666f21d0..ba3160ff7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java @@ -1457,12 +1457,10 @@ private static class StringReader { } int read() { - try { - return buf[pos++]; - } catch (ArrayIndexOutOfBoundsException e) { - pos = buf.length; + if (pos >= buf.length) { return -1; } + return buf[pos++]; } void reset() {