Closed
Description
I was looking over the str module and noticed that a lot of the functions there do unnecessary allocations. I counted ~20 functions that return either an ~str
or ~[~str]
where a &str
or a bunch of &str
would do. (they're mostly search / trim functions)
I'd like to change them, however I'm not sure if that would be the best way in regards to API design.
My proposal is:
- Every function that returns
~str
but could also return an&str
will get changed to do so. If users want to have an explicit copy, they have to callto_uniqe()
or similar. - Every function that returns an
~[~str]
but could also return return a list of&str
will get rewritten under an other name to work as an iterator that takes anfn(&str) -> bool
closure. The original name still remains, and will just wrap that iterator in an ~[~str]. - Remove the
view
functions, make theslice
ones return&str
(mirrors recent change tovec
)