PyTypeObject *bytestring_pytype;
+static PyObject *empty, *bytev[256];
+
static PyObject *allocate(PyTypeObject *ty, size_t n)
{
PyStringObject *x;
static PyObject *dowrap(PyTypeObject *ty, const void *p, size_t n)
{
PyObject *x;
+ int ch;
+
+ if (p && ty == bytestring_pytype) {
+ if (!n) {
+ if (!empty) empty = allocate(ty, 0);
+ Py_INCREF(empty); return (empty);
+ } else if (n == 1 && (ch = *(unsigned char *)p) < sizeof(bytev)) {
+ if (!bytev[ch])
+ { bytev[ch] = allocate(ty, 1); *PyString_AS_STRING(bytev[ch]) = ch; }
+ Py_INCREF(bytev[ch]); return (bytev[ch]);
+ }
+ }
x = allocate(ty, n);
if (p) memcpy(PyString_AS_STRING(x), p, n);