Repository navigation
refactor: write the minted hex a nibble at a time - #117
Conversation
random_hex formatted each byte through `write!` into a String. It now pushes the two digits itself, from a helper that names the four bits it is given, so the hot path takes no formatter and no fallible write.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
|
Both review rounds accounted for:
CI is green on |
random_hexformatted every random byte throughwrite!(out, "{byte:02x}")into aString. It now pushes the two digits itself, through ahex_digithelper that names thefour bits it is given.
Same alphabet (lowercase hex), same length (two characters per byte), same randomness
source (
getrandom::fill), sameString::with_capacityreservation, std only, no newdependency. The
#[expect(clippy::expect_used, …)]on the function and its doc comment areuntouched: the CSPRNG call is the one that can fail, and it still panics with the same
message.
The callers are unchanged:
mint_room_id(6 bytes),mint_token(16), and the per-connectionpeer id in
net/mod.rs(8).Tests
Three tests in
crates/selvaged/src/lib.rs, characterization only — nothing here wasbroken, so none of them fails against the old implementation:
a_mint_is_lowercase_hex_of_two_characters_a_byte— over sizes 0, 1, 6, 8, 16: length is2 * bytes, every character is0-9a-f.the_minted_identifiers_are_the_sizes_the_protocol_names—mint_room_idisr-plus 12hex digits,
mint_tokenis 32.two_mints_of_the_same_size_differ— the bytes are drawn, not left as the buffer's zeros.Gate
Run from the flake,
CARGO_BUILD_JOBS=2, one build at a time:The three new tests in that run:
The commit was made inside the dev shell, so the repository's hooks ran and passed
(
cargo check,cargo nextest,clippy,deny,rustfmt,lychee,typos,gitlint, …).Summary by CodeRabbit