This repository was archived by the owner on Nov 1, 2020. It is now read-only.
Change Decimal's fields to ints. #3838
Merged
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.
Change Decimal's fields to ints.
https://devdiv.visualstudio.com/DevDiv/_workitems?id=447645
The code was ported from DWORD-based C++ and expects to
see unsigned values. Serialization expects to see signed fields.
Fixing this in three steps:
Iteration #1: Use VS autorename to rename the "hi/med/lo/flags" to
"uhi/umed/ulo/uflags"
Iteration #2: Manually revert the field rename (but not the references
to them) and change their types to signed int. Add back the
"u" versions as unsigned ints overlaying the signed versions
and invisible to serialization.
Iteration #3: Opportunistically change a few "u" references
back to the original mostly to get rid of obviously unnecessary casts
to uint.. Doing this very conservatively - only
where it's dead obvious without knowing all the intricacies of
uint vs. int math and and where it wouldn't create local mismatches
of "u" vs non-"u" references. Ugly as this looks, I don't think
converting the entire codebase to signed is in the cards.
Other approaches rejected:
Implement a "ulo" property wrapping the "lo" field. Nope -
some code passes refs to these fields.
Implement a "private ref uint ulo => ref Unsafe.As<>..." property
No-can-do - C# notices that the field belongs to a struct
and won't let you pass around a ref to that so freely.