Redefine RepeatBehavior as readonly struct to prevent defensive copies #9776
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.
Description
Since
RepeatBehavior
is immutable by design, we should adjust it toreadonly struct
. This will also prevent defensive copies, even though the struct is small, it will already matter a bit here. It will also improve code quality. This is not a breaking change.Forever
property creation will be added.new TimeSpan(0)
is exactly whatTimeSpan.Zero
does but it is cleaner imho.Customer Impact
Possibly a bit of perf and a clear directive that
RepeatBehavior
and all its methods are not adjusting the state of thestruct
.Regression
No.
Testing
Local build, base testing, type creation, etc.
Risk
I do not asses any, since the struct is immutable and this is not a breaking change. It is a change to a public type but such changes have been done previously in runtime, see for example #97421.
Microsoft Reviewers: Open in CodeFlow