diff options
author | Fredrik Lundh <fredrik@pythonware.com> | 2006-05-22 17:12:58 (GMT) |
---|---|---|
committer | Fredrik Lundh <fredrik@pythonware.com> | 2006-05-22 17:12:58 (GMT) |
commit | 8a8e05a2b9c629827827295a7bd76494aed41b72 (patch) | |
tree | 16a684efaec310a8bd650509ab40c2e979a32e55 /Objects | |
parent | f1d60a53845d2efeccdb61bebf6ee8df94df16d4 (diff) | |
download | cpython-8a8e05a2b9c629827827295a7bd76494aed41b72.zip cpython-8a8e05a2b9c629827827295a7bd76494aed41b72.tar.gz cpython-8a8e05a2b9c629827827295a7bd76494aed41b72.tar.bz2 |
needforspeed: use memcpy for "long" strings; use a better algorithm
for long repeats.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/unicodeobject.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 6f04a6d..85cbed2 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -5900,11 +5900,18 @@ unicode_repeat(PyUnicodeObject *str, Py_ssize_t len) if (str->length == 1 && len > 0) { Py_UNICODE_FILL(p, str->str[0], len); - } else - while (len-- > 0) { + } else { + int done = 0; /* number of characters copied this far */ + if (done < nchars) { Py_UNICODE_COPY(p, str->str, str->length); - p += str->length; - } + done = str->length; + } + while (done < nchars) { + int n = (done <= nchars-done) ? done : nchars-done; + Py_UNICODE_COPY(p+done, p, n); + done += n; + } + } return (PyObject*) u; } |