Hi all, This patch optimizes repeat(text, int).
The current implementation constructs the result by copying the source text once per repetition. For larger repeat counts, that leads to many small memcpy() calls. This patch keeps the existing linear path for small repeat counts, and uses a doubling strategy for larger ones by repeatedly copying the already-generated prefix of the destination buffer. In local testing, this reduced total runtime in a small repeat()-focused microbenchmark, with the largest gains appearing in medium and large repeat count cases. Small-count cases did not show obvious regressions after keeping the original path below a small cutoff. The patch is attached. Thanks for your time, and any feedback would be appreciated. Best regards, Chenhui Mo
0001-speed-up-repeat-for-larger-counts.patch
Description: Binary data
