From 19ba389fe8194bb6c22102b32e021d8487e1e307 Mon Sep 17 00:00:00 2001 From: Sebastian Bazley Date: Thu, 29 Mar 2012 00:58:36 +0000 Subject: [PATCH] Checking the token type seems to be quite slow git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1306663 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/java/org/apache/commons/csv/CSVLexer.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/csv/CSVLexer.java b/src/main/java/org/apache/commons/csv/CSVLexer.java index e3effbdd..15307c37 100644 --- a/src/main/java/org/apache/commons/csv/CSVLexer.java +++ b/src/main/java/org/apache/commons/csv/CSVLexer.java @@ -136,14 +136,18 @@ class CSVLexer extends Lexer { * @throws IOException on stream access error */ private Token simpleTokenLexer(Token tkn, int c) throws IOException { - while (tkn.type == INVALID) { + // Faster to use while(true)+break than while(tkn.type == INVALID) + while (true) { if (isEndOfLine(c)) { tkn.type = EORECORD; + break; } else if (isEndOfFile(c)) { tkn.type = EOF; tkn.isReady = true; // There is data at EOF + break; } else if (isDelimiter(c)) { tkn.type = TOKEN; + break; } else if (isEscape(c)) { tkn.content.append((char) readEscape()); c = in.read(); // continue