Auto merge of #8641 - weihanglo:fix/remove-alloc, r=Eh2406
Auto merge of #8641 - weihanglo:fix/remove-alloc, r=Eh2406

fix: remove unnecessary allocations

Remove unnecessary `str::to_string` and `str::replace` allocations by using iterators. This PR is almost identical to #8622 except it does not skip the generated header.

Sorry that I did not profile the changes by myself. Seems that valgrind does not support macOS 10.15.6, I have not idea how to profile cargo subcommand. It would be great for an instruction to run a memory profiling for Rust program on macOS.

tshepang/cargo,rust-lang/cargo,eminence/cargo,rustyhorde/cargo,rustyhorde/cargo,nipunn1313/cargo,eminence/cargo,rust-lang/cargo,rust-lang/cargo,nipunn1313/cargo,rustyhorde/cargo,tshepang/cargo,tshepang/cargo,eminence/cargo,tshepang/cargo,rust-lang/cargo,eminence/cargo,rustyhorde/cargo,nipunn1313/cargo,nipunn1313/cargo