Skip to content

Commit 94b9f8d

Browse files
committed
Minor performance improvement (~2%)
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1299486 13f79535-47bb-0310-9956-ffa450edef68
1 parent 740a1b6 commit 94b9f8d

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

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

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -317,20 +317,20 @@ Token nextToken(Token tkn) throws IOException {
317317
c = in.readAgain();
318318

319319
// empty line detection: eol AND (last char was EOL or beginning)
320-
while (format.isEmptyLinesIgnored() && eol
321-
&& (lastChar == '\n'
322-
|| lastChar == '\r'
323-
|| lastChar == ExtendedBufferedReader.UNDEFINED)
324-
&& !isEndOfFile(lastChar)) {
325-
// go on char ahead ...
326-
lastChar = c;
327-
c = in.read();
328-
eol = isEndOfLine(c);
329-
c = in.readAgain();
330-
// reached end of file without any content (empty line at the end)
331-
if (isEndOfFile(c)) {
332-
tkn.type = EOF;
333-
return tkn;
320+
if (format.isEmptyLinesIgnored()) {
321+
while (eol
322+
&& (lastChar == '\n' || lastChar == '\r' || lastChar == ExtendedBufferedReader.UNDEFINED)
323+
&& !isEndOfFile(lastChar)) {
324+
// go on char ahead ...
325+
lastChar = c;
326+
c = in.read();
327+
eol = isEndOfLine(c);
328+
c = in.readAgain();
329+
// reached end of file without any content (empty line at the end)
330+
if (isEndOfFile(c)) {
331+
tkn.type = EOF;
332+
return tkn;
333+
}
334334
}
335335
}
336336

@@ -343,11 +343,14 @@ Token nextToken(Token tkn) throws IOException {
343343
// important: make sure a new char gets consumed in each iteration
344344
while (!tkn.isReady && tkn.type != EOF) {
345345
// ignore whitespaces at beginning of a token
346-
while (format.isLeadingSpacesIgnored() && isWhitespace(c) && !eol) {
347-
wsBuf.append((char) c);
348-
c = in.read();
349-
eol = isEndOfLine(c);
346+
if (format.isLeadingSpacesIgnored()) {
347+
while (isWhitespace(c) && !eol) {
348+
wsBuf.append((char) c);
349+
c = in.read();
350+
eol = isEndOfLine(c);
351+
}
350352
}
353+
351354
// ok, start of token reached: comment, encapsulated, or token
352355
if (c == format.getCommentStart()) {
353356
// ignore everything till end of line and continue (incr linecount)

0 commit comments

Comments
 (0)