Skip to content

perf(dpi/bittorrent): build format_version directly, drop per-byte String + Vec#349

Open
0xghost42 wants to merge 1 commit into
domcyrus:mainfrom
0xghost42:fix/bittorrent-format-version-alloc
Open

perf(dpi/bittorrent): build format_version directly, drop per-byte String + Vec#349
0xghost42 wants to merge 1 commit into
domcyrus:mainfrom
0xghost42:fix/bittorrent-format-version-alloc

Conversation

@0xghost42
Copy link
Copy Markdown
Contributor

Summary

Closes #348.

format_version (src/network/dpi/bittorrent.rs) mapped each kept byte to its own String, collected into a Vec<String>, then join(".") — one String allocation per byte plus the intermediate Vec on every client-version parse. The digit branch was redundant too: ASCII digits are a subset of ASCII alphanumerics, and (b - b'0').to_string() equals (b as char).to_string() for digit bytes.

Change

Keep ASCII-alphanumeric bytes and push b as char into a single pre-sized String, separating with .. Identical output, no per-byte String, no Vec.

Verification

cargo test --lib bittorrent — 41 passed, 0 failed (includes the existing version-format cases). cargo fmt clean.

…ring + Vec

format_version mapped each kept byte to its own String and collected into a
Vec<String> before join("."), allocating one String per byte plus the
intermediate Vec on every client-version parse. The digit branch was also
redundant (ASCII digits are a subset of alphanumerics and produce the same
char). Keep alphanumeric bytes and push b as char into a single pre-sized
String. Same output, no per-byte String, no Vec.

Closes domcyrus#348.
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.

perf(dpi/bittorrent): build format_version string directly, drop per-byte String + Vec

1 participant