Fix potential endianness and alignment problems with Span-based UnicodeTrie constructor - #284
Merged
JimBobSquarePants merged 1 commit intoJun 30, 2022
Conversation
…deTrie constructor
4 tasks
Member
|
Haha... You beat me by seconds. Was just committing to a branch with your changes! 😁 |
JimBobSquarePants
approved these changes
Jun 30, 2022
JimBobSquarePants
left a comment
Member
There was a problem hiding this comment.
Brilliant. Thanks! 👍
Codecov Report
@@ Coverage Diff @@
## main #284 +/- ##
=====================================
- Coverage 83% 83% -1%
=====================================
Files 222 222
Lines 12200 12199 -1
Branches 1756 1759 +3
=====================================
- Hits 10167 10159 -8
- Misses 1606 1610 +4
- Partials 427 430 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
Prerequisites
Description
This is a small PR making some changes to the recently-introduced
ReadOnlySpan<byte>constructor forUnicodeTrie. Currently, the data provided to this constructor is constant data generated via the RoslynROS<byte> = new byte[]trick, which doesn't guarantee alignment on the data. The data is also stored in little-endian, which requires swapping for big-endian platforms.UnicodeTrieHeaderis now a simple structure containing only fields, and it no longer has aStructLayoutattribute. Its layout won't result in padding, soPack = 1was removed.UnicodeTrieconstructor now readsUnicodeTrieHeaderwithMemoryMarshal.Read, to ensure there are no problems with alignment on platforms that require it (MemoryMarshal.Readperforms an unaligned read.)rawDataspan is no longerCasted touintbut rather the destinationuintarray is casted tobyte, for similar alignment-related reasons.