summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2002-04-21 18:15:20 (GMT)
committerTim Peters <tim.peters@gmail.com>2002-04-21 18:15:20 (GMT)
commite1682a80fa3a664715367bc09f467eb1bd1ce537 (patch)
treef43f5fa8fa9c565b7894a911b37cc05d9dd110a0 /Objects
parent0eca65c4c5ade46c960ea21e0827b051d0cd8bf7 (diff)
downloadcpython-e1682a80fa3a664715367bc09f467eb1bd1ce537.zip
cpython-e1682a80fa3a664715367bc09f467eb1bd1ce537.tar.gz
cpython-e1682a80fa3a664715367bc09f467eb1bd1ce537.tar.bz2
Py_UniversalNewlineFread(): small speed boost on non-Windows boxes.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/fileobject.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index 044dfd8..3dd1034 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -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
@@ -2076,7 +2077,6 @@ Py_UniversalNewlineFread(char *buf, size_t n,
else if (skipnextlf)
newlinetypes |= NEWLINE_CR;
*dst++ = c;
- --n;
skipnextlf = 0;
}
}