Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If `n` is the number of `substr` replace operations, the old implementation did `n+1` allocations and always first copied start, then replacement, then the remaining (unsearched) part of the original string. Now calculate the number of occurences of `substr` before allocating the resulting string. Change the algorithm to parse through the original string and only copy the parts that must be kept into the resulting string plus the replacements where they belong at. Now we also only have to go through the original string twice plus we only do a single allocation. Signed-off-by: Steffen Jaeckel <[email protected]>
- Loading branch information