From b20d7dbe861024ef7ad7a565c5d8e61ee2d8be81 Mon Sep 17 00:00:00 2001 From: Andrey Vorobiev Date: Wed, 1 Jan 2020 18:02:38 +0300 Subject: [PATCH] Do not use exceptions for control flow in StringTokenizer.lookAhead It's easier to check if we are out of buffer bounds and return '\0'. Motivation: - it's easier to debug cases when we need to set breakpoint on any exeception because we have a much less noise. - theoretically it should be a little bit faster. But I'm too lazy to write a benchmark. --- src/gov/nist/core/StringTokenizer.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/gov/nist/core/StringTokenizer.java b/src/gov/nist/core/StringTokenizer.java index 2b8067054..7849e1fea 100755 --- a/src/gov/nist/core/StringTokenizer.java +++ b/src/gov/nist/core/StringTokenizer.java @@ -134,12 +134,8 @@ public char lookAhead() throws ParseException { public char lookAhead(int k) throws ParseException { // Debug.out.println("ptr = " + ptr); - try { - return buffer[ptr + k]; - } - catch (IndexOutOfBoundsException e) { - return '\0'; - } + int index = ptr + k; + return index < buffer.length ? buffer[index] : '\0'; } public char getNextChar() throws ParseException {