perf(dpi/bittorrent): build format_version directly, drop per-byte String + Vec#349
Open
0xghost42 wants to merge 1 commit into
Open
perf(dpi/bittorrent): build format_version directly, drop per-byte String + Vec#3490xghost42 wants to merge 1 commit into
0xghost42 wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #348.
format_version(src/network/dpi/bittorrent.rs) mapped each kept byte to its ownString, collected into aVec<String>, thenjoin(".")— oneStringallocation per byte plus the intermediateVecon 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 charinto a single pre-sizedString, separating with.. Identical output, no per-byteString, noVec.Verification
cargo test --lib bittorrent— 41 passed, 0 failed (includes the existing version-format cases).cargo fmtclean.