-
-
Notifications
You must be signed in to change notification settings - Fork 123
perf(binary): unpack packed values through a byte-pair table #1214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
487ed86
bench(binary): cover the small stanza the wire is actually made of
jlucaso1 3783347
perf(binary): unpack packed values through a byte-pair table
jlucaso1 f9cd9a1
docs(binary): correct what the new benches actually cover
jlucaso1 374579d
test(binary): reject an invalid nibble from inside a chunk too
jlucaso1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| //! The packed-value tables must decode exactly what the scalar nibble/hex | ||
| //! walk did, including where an invalid nibble reports the failure. | ||
| use wacore_binary::builder::NodeBuilder; | ||
| use wacore_binary::marshal::{marshal, unmarshal_ref}; | ||
|
|
||
| fn roundtrip_attr(value: &str) -> String { | ||
| let node = NodeBuilder::new("t").attr("v", value).build(); | ||
| let bytes = marshal(&node).unwrap(); | ||
| let decoded = unmarshal_ref(&bytes[1..]).unwrap(); | ||
| match decoded.get_attr("v").unwrap() { | ||
| wacore_binary::node::ValueRef::String(s) => s.to_string(), | ||
| other => panic!("unexpected value {other:?}"), | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn packed_values_round_trip_across_the_simd_boundary() { | ||
| // Hex and nibble, at lengths below, at, and above the 16-byte chunk the | ||
| // SIMD path handles, plus odd lengths that exercise the half-byte trim. | ||
| for len in [1, 2, 3, 15, 16, 17, 31, 32, 33, 63, 100, 127] { | ||
| let hex: String = (0..len) | ||
| .map(|i| b"0123456789ABCDEF"[i % 16] as char) | ||
| .collect(); | ||
| assert_eq!(roundtrip_attr(&hex), hex, "hex len {len}"); | ||
|
|
||
| let nibble: String = (0..len).map(|i| b"0123456789-."[i % 12] as char).collect(); | ||
| assert_eq!(roundtrip_attr(&nibble), nibble, "nibble len {len}"); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn an_invalid_nibble_is_still_rejected() { | ||
| // Nibble 12, 13 and 14 encode nothing. Build the frame by hand, since the | ||
| // encoder would never emit one. | ||
| for bad in [0x0Cu8, 0x0D, 0x0E] { | ||
| // NIBBLE_8 tag, length 1, one byte whose low half is invalid. | ||
| let frame = [248u8, 2, 1, 255, 1, 0xF0 | bad]; | ||
|
jlucaso1 marked this conversation as resolved.
Outdated
|
||
| let err = unmarshal_ref(&frame).unwrap_err(); | ||
| assert!( | ||
| format!("{err}").contains(&bad.to_string()), | ||
| "error must name the bad nibble {bad}: {err}" | ||
| ); | ||
| } | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.