needforspeed: use memcpy for "long" strings; use a better algorithm

for long repeats.
This commit is contained in:
Fredrik Lundh 2006-05-22 17:12:58 +00:00
parent f1d60a5384
commit 8a8e05a2b9
2 changed files with 20 additions and 8 deletions

View file

@ -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;
}