Speed up Screen.draw

This commit is contained in:
Kovid Goyal 2023-11-16 14:38:46 +05:30
parent c2d81d67c2
commit 43fb09dc39
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C

View file

@ -3541,10 +3541,10 @@ static PyObject*
draw(Screen *self, PyObject *src) {
if (!PyUnicode_Check(src)) { PyErr_SetString(PyExc_TypeError, "A unicode string is required"); return NULL; }
if (PyUnicode_READY(src) != 0) { return PyErr_NoMemory(); }
int kind = PyUnicode_KIND(src);
void *buf = PyUnicode_DATA(src);
Py_ssize_t sz = PyUnicode_GET_LENGTH(src);
for (Py_ssize_t i = 0; i < sz; i++) draw_codepoint(self, PyUnicode_READ(kind, buf, i), true);
Py_UCS4 *buf = PyUnicode_AsUCS4Copy(src);
if (!buf) return NULL;
draw_text(self, buf, PyUnicode_GetLength(src));
PyMem_Free(buf);
Py_RETURN_NONE;
}