[Python-checkins] r68617 - sandbox/trunk/io-c/_textio.c
antoine.pitrou
python-checkins at python.org
Thu Jan 15 16:43:14 CET 2009
Author: antoine.pitrou
Date: Thu Jan 15 16:43:14 2009
New Revision: 68617
Log:
Speedup TextIOWrapper.write() a bit
Modified:
sandbox/trunk/io-c/_textio.c
Modified: sandbox/trunk/io-c/_textio.c
==============================================================================
--- sandbox/trunk/io-c/_textio.c (original)
+++ sandbox/trunk/io-c/_textio.c Thu Jan 15 16:43:14 2009
@@ -567,9 +567,10 @@
if (newline)
self->readnl = PyUnicode_FromString(newline);
self->writetranslate = (newline == NULL || newline[0] != '\0');
- if (!self->readuniversal) {
- if (self->readnl)
- self->writenl = _PyUnicode_AsString(self->readnl);
+ if (!self->readuniversal && self->readnl) {
+ self->writenl = _PyUnicode_AsString(self->readnl);
+ if (!strcmp(self->writenl, "\n"))
+ self->writenl = NULL;
}
#ifdef MS_WINDOWS
else
@@ -743,7 +744,7 @@
textlen = PyUnicode_GetSize(text);
- if (self->writetranslate || self->line_buffering)
+ if ((self->writetranslate && self->writenl != NULL) || self->line_buffering)
if (findchar(PyUnicode_AS_UNICODE(text),
PyUnicode_GET_SIZE(text), '\n'))
haslf = 1;
@@ -764,19 +765,19 @@
needflush = 1;
/* XXX What if we were just reading? */
- b = PyObject_CallMethod(self->encoder, "encode", "O", text);
+ b = PyObject_CallMethodObjArgs(self->encoder, _PyIO_str_encode, text, NULL);
Py_DECREF(text);
if (b == NULL)
return NULL;
- ret = PyObject_CallMethod(self->buffer, "write", "O", b);
+ ret = PyObject_CallMethodObjArgs(self->buffer, _PyIO_str_write, b, NULL);
Py_DECREF(b);
if (ret == NULL)
return NULL;
Py_DECREF(ret);
if (needflush) {
- ret = PyObject_CallMethod(self->buffer, "flush", NULL);
+ ret = PyObject_CallMethodObjArgs(self->buffer, _PyIO_str_flush, NULL);
if (ret == NULL)
return NULL;
Py_DECREF(ret);
More information about the Python-checkins
mailing list