Skip to content

Commit 19ba389

Browse files
committed
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
1 parent 810c8d0 commit 19ba389

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/main/java/org/apache/commons/csv/CSVLexer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,18 @@ Token nextToken(Token tkn) throws IOException {
136136
* @throws IOException on stream access error
137137
*/
138138
private Token simpleTokenLexer(Token tkn, int c) throws IOException {
139-
while (tkn.type == INVALID) {
139+
// Faster to use while(true)+break than while(tkn.type == INVALID)
140+
while (true) {
140141
if (isEndOfLine(c)) {
141142
tkn.type = EORECORD;
143+
break;
142144
} else if (isEndOfFile(c)) {
143145
tkn.type = EOF;
144146
tkn.isReady = true; // There is data at EOF
147+
break;
145148
} else if (isDelimiter(c)) {
146149
tkn.type = TOKEN;
150+
break;
147151
} else if (isEscape(c)) {
148152
tkn.content.append((char) readEscape());
149153
c = in.read(); // continue

0 commit comments

Comments
 (0)