Skip to content

Missed optimization because of missing inline attr on OsStr #67150

Closed
@tesuji

Description

@tesuji

Godbolt link: https://rust.godbolt.org/z/bAU2UA
I expect these two snippets have the same optimized asm but they don't:

use std::ffi::OsStr;

pub fn foo(s: Option<&OsStr>) -> bool {
    s.map_or(false, |x| x == OsStr::new("so"))
}
use std::ffi::OsStr;

pub fn foo(s: Option<&OsStr>) -> bool {
    s == Some(OsStr::new("so"))
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions