STINNER Victor added the comment:
> Looks like it's cheaper to overallocate than add checks for overflow at each
> loop iteration.
I expected that the temporary Py_UCS4 buffer and the conversion to a Unicode
object (Py_UCS1, Py_UCS2 or Py_UCS4) would be more expensive than
_PyUnicodeWriter. It looks like it's slower.
I tried to optimize the code but I didn't see how to make it really faster than
the current code.
--
Currently, the code uses:
for (j = 0; j < n_res; j++) {
*maxchar = Py_MAX(*maxchar, mapped[j]);
res[k++] = mapped[j];
}
where res is a Py_UCS4* string, and mapped an array of 3 Py_UCS4.
I replaced it with a call to case_operation_write() which calls
_PyUnicodeWriter_WriteCharInline().
_PyUnicodeWriter_WriteCharInline() is maybe more expensive than "res[k++] =
mapped[j];".
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue22649>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com