Skip to content

Concat trait has bad codegen for arrays #82164

@taralx

Description

@taralx

Code: https://rust.godbolt.org/z/TjPcbz

use std::convert::TryInto;

pub fn t(a: [u8; 32], b: [u8; 32]) -> [u8; 64] {
    [a, b].concat().try_into().unwrap()
}

This shouldn't allocate. Nor should it be doing anywhere near as many copies. Even if you remove the Vec -> array conversion, it's still doing way more work than it needs to -- the grow calls should not be there for a simple concat.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-arrayArea: `[T; N]`C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchI-slowIssue: Problems and improvements with respect to performance of generated code.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions