summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaša Živkov <sasa.zivkov@sap.com>2019-09-27 15:58:10 +0200
committerSaša Živkov <sasa.zivkov@sap.com>2019-09-27 15:58:10 +0200
commit3d8649ddef2874aeea7e3e83b47e5fd4867c5cd5 (patch)
treead73af9197b84974378e38f2e811e023206b8e99
parente3f535cb15a75d6b2448bfadbc9839da8085f1ec (diff)
downloadjgit-3d8649ddef2874aeea7e3e83b47e5fd4867c5cd5.tar.gz
jgit-3d8649ddef2874aeea7e3e83b47e5fd4867c5cd5.zip
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
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java6
1 files 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 b666f21d0b..ba3160ff76 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 @@ public class Config {
}
int read() {
- try {
- return buf[pos++];
- } catch (ArrayIndexOutOfBoundsException e) {
- pos = buf.length;
+ if (pos >= buf.length) {
return -1;
}
+ return buf[pos++];
}
void reset() {