3 ms·
Your code is a bit inefficient. I took the liberty of fixing that for you: https://gist.github.com/lhecker/8e89d998c156f0bfdd2d https://gist.github.com/lhecker/
by lhecker 11y ago
Your code is a bit inefficient. I took the liberty of fixing that for you: https://gist.github.com/lhecker/8e89d998c156f0bfdd2d https://gist.github.com/lhecker/8e89d998c156f0bfdd2d
(You can use that code freely and without any attribution if you want to.)
The important part here is to use `String::with_capacity()` to prevent unnecessary reallocations. Furthermore I used `usize::saturating_sub()` because it's neat and cleaned up the code with `rustfmt` (which you should use).
- hub_ 11y agoa PR is more practical if you want me to merge. Thanks !
- hub_ 11y agobtw, creating the string with capacity was in my mind at one point. Some contributor submitted a PR already https://github.com/hfiguiere/leftpad-rs/pull/2 https://github.com/hfiguiere/leftpad-rs/pull/2 Sadly it has gathered some rust (pun intended !)