-
-
Notifications
You must be signed in to change notification settings - Fork 977
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
refactor: Nullable and Modernization for Core projects #2643
Open
Kryptos-FR
wants to merge
16
commits into
stride3d:master
Choose a base branch
from
Color-Rise:feature/modernize-code
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains 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
c023453
to
b133105
Compare
sources/core/Stride.Core.CompilerServices/Generators/ModuleInitializerGenerator.cs
Show resolved
Hide resolved
Note: I will do a few more projects in that PR ( |
8e01cdb
to
f3a7b5a
Compare
8 tasks
f3a7b5a
to
8c62e52
Compare
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.
PR Details
Similar to #2639.
Description
As in the previous PR, enable C# built-in nullable annotations on the project and remove references to our old custom ones. In addition, modernization of the code (pattern matching, file-scoped namespaces, collection initialization, etc.
Equals
Worth of note is a fix of the
Equals(object?)
implementation for some structs inCore.Mathematics
. While it was unlikely to be used (as the same structs also define a type version ofEquals
), the implementation was doing unnecessary checks and struct boxing (which also had Resharper detect the implementation as mutating).Consider the previous implementation for
Vector3
:The corresponding IL code is:
We can clearly see the virtual calls necessary for comparing the types as well as the boxing required for such call.
The new implementation is simpler:
And the corresponding IL also:
Hashcode
Another point of improvement is the computation of hashcodes. In lots of places we had a custom implementation that wasn't necessary efficient or even correct (sometimes it was missing the
unchecked
context). .NET provides a battle-tested implementation with the right properties and efficiency.Our previous implementation for
Matrix
:Now, using
Hashcode.Combine
:Swapping
Another fun improvement is how to swap two values. The usual implementation was to use a temporary variable:
We can now use a value tuple:
In my opinion it does improve readability when applied to
Matrix.Transpose
.Before:
After:
Related Issue
#2155
#2156
Types of changes
Checklist