Skip to content

Double count after finding new line and return #1

Description

@TheFern2

Hey man,

I found your repo and it just what I needed to index a big text file is it is fast my biggest file has around 60,000 lines and it ran in less than a sec.

I ran your tests, and some of the test are failing due to calling incrementCounters() twice when \n and \r is found. Anyways I'll try to get this fixed after running a few more tests.

At line 55 on FileLinesIterator:

while (true) {
            if (!refillBufferIfNeeded()) break;
            final char nextChar = (char) buffer[positionInBuffer];
            if (!isLineDelimiter(nextChar)) {
                stringBuilder.append(nextChar);   
            } else if (isCarriageReturnFollowedByLineFeed(nextChar)) {
                incrementCounters();
            }
            
            incrementCounters(); // BUG This is counting lineLenght twice at \r and \n
            
        
			if (isLineDelimiter(nextChar)) break;
        }
        if (lineLength == 0) {
            closeInputStream();
            throw new NoSuchElementException();
        }
        return line(stringBuilder.toString(), lineLength);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions