Skip to content

cli: use split_at() in parse_human_readable_size() - #3545

Open
Ibitier wants to merge 1 commit into
BurntSushi:masterfrom
Ibitier:parse-size-with-split-at
Open

Ibitier wants to merge 1 commit into
BurntSushi:masterfrom
Ibitier:parse-size-with-split-at

Conversation

@Ibitier

@Ibitier Ibitier commented Sep 24, 2026

Copy link
Copy Markdown

Replace two separate slice operations (&size[..digits_end] and &size[digits_end..]) with a single split_at(digits_end) call.

The Rust compiler has a dedicated optimization for split_at() that emits only one bounds check and fewer instructions compared to two independent slices (verified with cargo asm on x86_64-unknown-linux-gnu).

This function is not hot code, so the performance difference is negligible. But it uses a standard library function so it is arguably more idiomatic and readable.

Replace two separate slice operations (&size[..digits_end] and
&size[digits_end..]) with a single split_at(digits_end) call.

The Rust compiler has a dedicated optimization for split_at() that
emits only one bounds check and fewer instructions compared to two
independent slices (verified with cargo asm on
x86_64-unknown-linux-gnu).

This function is not hot code, so the performance difference is
negligible. But it uses a standard library function so it is more
idiomatic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant