Skip to content

str module allocates too much; proposal for improvement #5427

Closed
@Kimundi

Description

@Kimundi

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 call to_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 an fn(&str) -> bool closure. The original name still remains, and will just wrap that iterator in an ~[~str].
  • Remove the view functions, make the slice ones return &str (mirrors recent change to vec)

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-slowIssue: Problems and improvements with respect to performance of generated code.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions