]> source.dussan.org Git - jgit.git/commitdiff
Do not rely on ArrayIndexOutOfBoundsException to detect end of input 54/150254/1
authorSaša Živkov <sasa.zivkov@sap.com>
Fri, 27 Sep 2019 13:58:10 +0000 (15:58 +0200)
committerSaša Živkov <sasa.zivkov@sap.com>
Fri, 27 Sep 2019 13:58:10 +0000 (15:58 +0200)
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

index b666f21d0b2bbceff7e63bfc383934037a006e35..ba3160ff76f0d49c2ada845d0fe5d5d5561eda7d 100644 (file)
@@ -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() {