Skip to content

get_short_name should return a Cow most likely #2

@nicopap

Description

@nicopap

What problem does this solve or what need does it fill?

bevy_utils::get_short_name returns a String. This results in unconditional allocation, even if the short name can be expressed as a slice of the full name.

What solution would you like?

Returning a Cow (similarly to how from_utf8_lossy works) would reduce allocation.

What alternative(s) have you considered?

Sometimes, get_short_name is used for debug/display purposes. We could also provide a wrapper type that specifically implements Display for &str with the get_short_name heuristic to remove all type prefixes.

Additional context

I saw a "hand made" version of get_short_name in a fmt::Debug impl in asset_v2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions