Kaydet (Commit) e1682a80 authored tarafından Tim Peters's avatar Tim Peters

Py_UniversalNewlineFread(): small speed boost on non-Windows boxes.

üst 0eca65c4
...@@ -2052,19 +2052,20 @@ Py_UniversalNewlineFread(char *buf, size_t n, ...@@ -2052,19 +2052,20 @@ Py_UniversalNewlineFread(char *buf, size_t n,
nread = fread(dst, 1, n, stream); nread = fread(dst, 1, n, stream);
assert(nread <= n); 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--) { while (nread--) {
char c = *src++; char c = *src++;
if (c == '\r') { if (c == '\r') {
/* Save as LF and set flag to skip next LF. */ /* Save as LF and set flag to skip next LF. */
*dst++ = '\n'; *dst++ = '\n';
--n;
skipnextlf = 1; skipnextlf = 1;
} }
else if (skipnextlf && c == '\n') { else if (skipnextlf && c == '\n') {
/* Skip LF, and remember we saw CR LF. */ /* Skip LF, and remember we saw CR LF. */
skipnextlf = 0; skipnextlf = 0;
newlinetypes |= NEWLINE_CRLF; newlinetypes |= NEWLINE_CRLF;
++n;
} }
else { else {
/* Normal char to be stored in buffer. Also /* Normal char to be stored in buffer. Also
...@@ -2076,7 +2077,6 @@ Py_UniversalNewlineFread(char *buf, size_t n, ...@@ -2076,7 +2077,6 @@ Py_UniversalNewlineFread(char *buf, size_t n,
else if (skipnextlf) else if (skipnextlf)
newlinetypes |= NEWLINE_CR; newlinetypes |= NEWLINE_CR;
*dst++ = c; *dst++ = c;
--n;
skipnextlf = 0; skipnextlf = 0;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment