Dennis Sweeney <[email protected]> added the comment:
I'd bet we could add a couple of utility functions that could be used in
multiple places, to keep the "trick" all in one place. Something like
void
_PyBytes_RepeatInPlace(char **buffer, size_t start_len, size_t end_len)
{
// Repeatedly double.
size_t copied = start_len;
while (copied < end_len) {
size_t to_copy = Py_MIN(copied, end_len - copied);
memcpy(buffer + copied, buffer, to_copy);
copied += to_copy;
}
}
void
_PyBytes_Repeat(char *dest, size_t len_dest,
const char *src, size_t len_src)
{
// XXX maybe handle zero lengths
// XXX maybe use memset for len_src == 1
memcpy(dest, src, len_src);
_PyBytes_RepeatInPlace(dest, len_src, len_dest);
}
----------
nosy: +Dennis Sweeney
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue47070>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com