Skip to content

Commit

Permalink
Py_UniversalNewlineFread(): small speed boost on non-Windows boxes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-one committed Apr 21, 2002
1 parent 0eca65c commit e1682a8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Objects/fileobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2052,19 +2052,20 @@ Py_UniversalNewlineFread(char *buf, size_t n,

nread = fread(dst, 1, n, stream);
assert(nread <= n);
shortread = nread != n; /* true iff EOF or error */
n -= nread; /* assuming 1 byte out for each in; will adjust */
shortread = n != 0; /* true iff EOF or error */
while (nread--) {
char c = *src++;
if (c == '\r') {
/* Save as LF and set flag to skip next LF. */
*dst++ = '\n';
--n;
skipnextlf = 1;
}
else if (skipnextlf && c == '\n') {
/* Skip LF, and remember we saw CR LF. */
skipnextlf = 0;
newlinetypes |= NEWLINE_CRLF;
++n;
}
else {
/* Normal char to be stored in buffer. Also
Expand All @@ -2076,7 +2077,6 @@ Py_UniversalNewlineFread(char *buf, size_t n,
else if (skipnextlf)
newlinetypes |= NEWLINE_CR;
*dst++ = c;
--n;
skipnextlf = 0;
}
}
Expand Down

0 comments on commit e1682a8

Please sign in to comment.