Skip to content
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

Redefine RepeatBehavior as readonly struct to prevent defensive copies #9776

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

h3xds1nz
Copy link
Contributor

@h3xds1nz h3xds1nz commented Sep 13, 2024

Description

Since RepeatBehavior is immutable by design, we should adjust it to readonly 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.

  • A private constructor for the static Forever property creation will be added.
  • new TimeSpan(0) is exactly what TimeSpan.Zero does but it is cleaner imho.
  • Some code cleanup included.

Customer Impact

Possibly a bit of perf and a clear directive that RepeatBehavior and all its methods are not adjusting the state of the struct.

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

@h3xds1nz h3xds1nz requested review from a team as code owners September 13, 2024 12:28
@dotnet-policy-service dotnet-policy-service bot added PR metadata: Label to tag PRs, to facilitate with triage Community Contribution A label for all community Contributions labels Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant