3 ms·
`str::replace(from, to)` replaces all instances of the pattern `from` in the string with `to` returning the result as a newly allocated String. In theory the c
by mastax 5y ago
`str::replace(from, to)` replaces all instances of the pattern `from` in the string with `to` returning the result as a newly allocated String.
In theory the compiler could notice that the spaces added to the newly allocated strings are only used to influence the behavior of `split_whitespace` and do not otherwise affect the output of the function. In practice, it does not: https://rust.godbolt.org/z/z573Mvjzz https://rust.godbolt.org/z/z573Mvjzz The compiler does not decide to inline the call to `replace` and therefore does not do any special reasoning about it.