mirror of
https://github.com/apple/swift-crypto
synced 2026-11-23 04:34:21 +00:00
### Motivation The use of `Data.subdata(in:)` results in needless copies when decoding fields from bytes. Additionally, the use of a long chain of `Data.append(_:)` without a call to `Data.init(capacity:)` or `Data.reserveCapacity(_:)` can result in needless reallocations. ### Modifications - Remove unused `EncodeInt` and `DecodeInt` functions. They were unused before this PR but are there from when ARC credential serialization included the presentation limit. `DecodeInt` also happened to be incorrect and would crash when called with a slice. - Add some useful utility methods for popping bytes from a view without copying. - Add some generic functions for encoding and decoding `FixedWidthInteger` types along with tests for concrete types over `Data` and slices. - In ARC decoding, replace the use of `Data.subdata(in:)` with code that uses the `Data.Subsequence` slice (which happens to be `Data` since the type is self-slicing). - In ARC encoding, reserve enough capacity in the resulting `Data` when the sizes are known to reduce allocations. ## Results More performant serialization and deserialization for ARC types.