The optimized count implementation was counting newline characters
instead of actual lines, returning incorrect results for files that
don't end with a newline (which is common for source code files).
For example, a file with content "line1\nline2\nline3" (3 lines)
was returning 2 instead of 3.
The fix tracks the last byte read and adds 1 at EOF if the file
has content but doesn't end with a newline.