Apply fixes and speedups

This commit is contained in:
Justine Tunney 2021-10-04 03:23:31 -07:00
parent 7521bf9e73
commit 725f4d79f6
36 changed files with 682 additions and 334 deletions

View file

@ -5,6 +5,7 @@
https://docs.python.org/3/license.html │
*/
#define PY_SSIZE_T_CLEAN
#include "libc/bits/bits.h"
#include "libc/fmt/fmt.h"
#include "libc/nexgen32e/kompressor.h"
#include "third_party/python/Include/floatobject.h"
@ -404,7 +405,7 @@ unicodedata_UCD_decomposition_impl(PyObject *self, int chr)
/* high byte is number of hex bytes (usually one or two), low byte
is prefix code (from*/
count = _PyUnicode_Bextr(_PyUnicode_Decomp, index, _PyUnicode_DecompBits) >> 8;
count = bextra(_PyUnicode_Decomp, index, _PyUnicode_DecompBits) >> 8;
/* XXX: could allocate the PyString up front instead
(strlen(prefix) + 5 * count + 1 bytes) */
@ -412,7 +413,7 @@ unicodedata_UCD_decomposition_impl(PyObject *self, int chr)
/* Based on how index is calculated above and _PyUnicode_Decomp is
generated from Tools/unicode/makeunicodedata.py, it should not be
possible to overflow _PyUnicode_DecompPrefix. */
prefix_index = _PyUnicode_Bextr(_PyUnicode_Decomp, index, _PyUnicode_DecompBits) & 255;
prefix_index = bextra(_PyUnicode_Decomp, index, _PyUnicode_DecompBits) & 255;
assert(prefix_index < Py_ARRAY_LENGTH(_PyUnicode_DecompPrefix));
/* copy prefix */
@ -424,8 +425,8 @@ unicodedata_UCD_decomposition_impl(PyObject *self, int chr)
decomp[i++] = ' ';
assert(i < sizeof(decomp));
PyOS_snprintf(decomp + i, sizeof(decomp) - i, "%04X",
_PyUnicode_Bextr(_PyUnicode_Decomp, ++index,
_PyUnicode_DecompBits));
bextra(_PyUnicode_Decomp, ++index,
_PyUnicode_DecompBits));
i += strlen(decomp + i);
}
return PyUnicode_FromStringAndSize(decomp, i);