Skip to content

Commit 84d77d3

Browse files
Make special case parsing logic for ints 1-3 bytes in length (#962)
* Make special case parsing logic for ints 1-3 bytes in length * Special case for the empty slice * Explain number of special cases Co-authored-by: Joshua Barr <[email protected]>
1 parent a1a9835 commit 84d77d3

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/binary/uint.rs

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ impl DecodedUInt {
2727
0 => Ok(0u128),
2828
// If the slice has 1-3 bytes, perform the conversion manually to avoid the `memcpy`
2929
// call made by the general-purpose conversion logic.
30+
// The aim is to allow the most common cases to be inlined by the caller. If we try
31+
// to special case too many integer sizes, then code generated for `uint_from_slice`
32+
// itself gets too large, and neither `uint_from_slice` nor `memcpy` get inlined.
3033
1 => Ok(uint_bytes[0] as u128),
3134
2 => Ok(u16::from_le_bytes([uint_bytes[1], uint_bytes[0]]) as u128),
3235
3 => Ok(u32::from_le_bytes([uint_bytes[2], uint_bytes[1], uint_bytes[0], 0u8]) as u128),

0 commit comments

Comments
 (0)