[Python-3000] characters data type

Fredrik Lundh fredrik at pythonware.com
Thu May 4 22:04:27 CEST 2006


Josiah Carlson wrote:

> I just thought of a better way of benchmarking list-like over-allocation
> semantics.

here's another way:

$ more Objects/unicodeobject.c
...
PyObject *
PyUnicode_Join(PyObject *separator, PyObject *seq)
{
    size_t res_alloc = 100;  /* # allocated bytes for string in res */
...
        if (new_res_used > res_alloc) {
            /* double allocated size until it's big enough */
            do {
                size_t oldsize = res_alloc;
                res_alloc += res_alloc;
                if (res_alloc < oldsize || res_alloc > INT_MAX)
                    goto Overflow;
            } while (new_res_used > res_alloc);
            if (_PyUnicode_Resize(&res, (int)res_alloc) < 0) {
                Py_DECREF(item);
                goto onError;
            }
            res_p = PyUnicode_AS_UNICODE(res) + res_used;
        }
...

</F>





More information about the Python-3000 mailing list