Skip to content

Remove redundant checks#59310

Merged
eerhardt merged 2 commits intodotnet:mainfrom
mapogolions:remove-redundant-checks
Sep 28, 2021
Merged

Remove redundant checks#59310
eerhardt merged 2 commits intodotnet:mainfrom
mapogolions:remove-redundant-checks

Conversation

@mapogolions
Copy link
Contributor

No description provided.

@ghost ghost added community-contribution Indicates that the PR has been added by a community member area-Extensions-Caching labels Sep 18, 2021
@ghost
Copy link

ghost commented Sep 18, 2021

Tagging subscribers to this area: @eerhardt, @maryamariyan, @michaelgsharp
See info in area-owners.md if you want to be subscribed.

Issue Details

null

Author: mapogolions
Assignees: -
Labels:

area-Extensions-Caching, community-contribution

Milestone: -

@eerhardt eerhardt requested a review from adamsitnik September 20, 2021 15:05
@eerhardt
Copy link
Member

I'm not seeing how this is a redundant check. @mapogolions, can you explain why this is redundant?

@mapogolions
Copy link
Contributor Author

mapogolions commented Sep 20, 2021

@eerhardt
If an absolute expiration value will be assigned to the cache entry and

  1. assigned value will not be modified in any way after the reading in this line of code
    then in this line the value is compared to itself
  2. assigned value will be modified somehow after the reading in the line of code specified above. The dependent entry propagates an absolute expiration to the parent only if this value is less than the parent value According this

I also thought that if I did something wrong, then the existing quality wall should have rejected my changes.

@eerhardt
Copy link
Member

Ok, I think I get it now. It does look like checking for entry.AbsoluteExpiration and resetting entry.AbsoluteExpiration back to itself is redundant.

@adamsitnik @Tratcher - any thoughts here?

I also thought that if I did something wrong, then the existing quality wall should have rejected my changes.

I think the other way holds - if the existing quality wall rejects your changes, you did something wrong. But it isn't guaranteed that there are tests for every scenario. We strive for it, but it isn't guaranteed.

@Tratcher
Copy link
Member

I had to stare at it for a few minutes but the change looks correct.

if (entry.AbsoluteExpirationRelativeToNow.HasValue)
{
if (!entry.AbsoluteExpiration.HasValue || absoluteExpiration.Value < entry.AbsoluteExpiration.Value)
var absoluteExpiration = utcNow + entry.AbsoluteExpirationRelativeToNow.Value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this library also ships in a .NET Standard flavor, it may be better to use Nullable<T>.GetValueOrDefault() instead of Nullable<T>.Value when Nullable<T>.HasValue returned true.

In .NET 6.0, the JIT was optimized to handle this (see @stephentoub's great blog post). The JIT in older versions of the .NET (and .NET Framework) does not have this optimization though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do this in a follow up PR, if necessary.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the contribution.

@eerhardt eerhardt merged commit ea0d4c4 into dotnet:main Sep 28, 2021
@pentp pentp mentioned this pull request Oct 1, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-Extensions-Caching community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants