Commit c28e2e53 authored by Antoine Pitrou's avatar Antoine Pitrou

In text I/O, optimize scanning for new lines with 1-byte unicode chars

parent f364e7b5
...@@ -365,6 +365,9 @@ _PyIncrementalNewlineDecoder_decode(PyObject *_self, ...@@ -365,6 +365,9 @@ _PyIncrementalNewlineDecoder_decode(PyObject *_self,
*/ */
if (seennl == 0 && if (seennl == 0 &&
memchr(in_str, '\n', kind * len) != NULL) { memchr(in_str, '\n', kind * len) != NULL) {
if (kind == PyUnicode_1BYTE_KIND)
seennl |= SEEN_LF;
else {
Py_ssize_t i = 0; Py_ssize_t i = 0;
for (;;) { for (;;) {
Py_UCS4 c; Py_UCS4 c;
...@@ -380,6 +383,7 @@ _PyIncrementalNewlineDecoder_decode(PyObject *_self, ...@@ -380,6 +383,7 @@ _PyIncrementalNewlineDecoder_decode(PyObject *_self,
break; break;
} }
} }
}
/* Finished: we have scanned for newlines, and none of them /* Finished: we have scanned for newlines, and none of them
need translating */ need translating */
} }
...@@ -1597,6 +1601,10 @@ textiowrapper_read(textio *self, PyObject *args) ...@@ -1597,6 +1601,10 @@ textiowrapper_read(textio *self, PyObject *args)
static char * static char *
find_control_char(int kind, char *s, char *end, Py_UCS4 ch) find_control_char(int kind, char *s, char *end, Py_UCS4 ch)
{ {
if (kind == PyUnicode_1BYTE_KIND) {
assert(ch < 256);
return (char *) memchr((void *) s, (char) ch, end - s);
}
for (;;) { for (;;) {
while (PyUnicode_READ(kind, s, 0) > ch) while (PyUnicode_READ(kind, s, 0) > ch)
s += kind; s += kind;
......
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