Uploaded image for project: 'Commons CSV'
  1. Commons CSV
  2. CSV-283

Remove Whitespace Check Determines Delimiter Twice

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.9.0
    • Component/s: None
    • Labels:
      None

      Description

      Lexer.java
          /**
           * Tests if the given char is a whitespace character.
           *
           * @return true if the given char is a whitespace character.
           * @throws IOException If an I/O error occurs.
           */
          boolean isWhitespace(final int ch) throws IOException {
              return !isDelimiter(ch) && Character.isWhitespace((char) ch);
          }
      
                          while (true) {
                              c = reader.read();
                              if (isDelimiter(c)) {
                                  token.type = TOKEN;
                                  return token;
                              }
                              if (isEndOfFile(c)) {
                                  ...
                              }
                              if (readEndOfLine(c)) {
                                  ...
                              }
                              if (!isWhitespace(c)) {
                                  // error invalid char between token and next delimiter
                                  throw new IOException("(line " + getCurrentLineNumber() +
                                          ") invalid char between encapsulated token and delimiter");
                              }
                          }
      

      So the first check is for the delimiter, and it returns quick if it finds it. After that point, it's known that this is NOT a delimiter, so no need to re-check it in isWhiteSpace. The delimiter check can be somewhat expensive given it may involve a look-ahead IO read.

      Remove the redundancy.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              belugabehr David Mollitor
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 20m
                20m