hfiguiere / leftpad-rs

leftpad, in rust.
BSD 2-Clause "Simplified" License
17 stars 7 forks source link

Presize the buffer #2

Closed ghost closed 7 years ago

ghost commented 8 years ago

presizes the buffer to avoid re-allocations while padding.

hfiguiere commented 8 years ago

Thanks !

ConnyOnny commented 7 years ago

This is wrong for more complicated pad chars. It should be s.as_bytes().len() + (pad as usize) * padchar.len_utf8()

EDIT: And this misses a cmp::max in there. I'll create another PR...

EDIT2: Done. PR #6 supersedes this PR.