Skip to content

Commit

Permalink
Different approach for equality check ignoring indices
Browse files Browse the repository at this point in the history
  • Loading branch information
mavasani committed Jul 18, 2023
1 parent b8c9389 commit 2a58a22
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,29 +204,8 @@ or PointsToAbstractValueKind.UnknownNull

public bool IsLValueFlowCaptureEntity => CaptureId.HasValue && CaptureId.Value.IsLValueFlowCapture;

internal bool EqualsIgnoringIndices(AnalysisEntity? other)
{
// Perform fast equality checks first.
if (ReferenceEquals(this, other))
{
return true;
}

if (other == null ||
EqualsIgnoringInstanceLocationId != other.EqualsIgnoringInstanceLocationId)
{
return false;
}

// Now perform slow check that compares individual hash code parts sequences.
return Symbol.GetHashCodeOrDefault() == other.Symbol.GetHashCodeOrDefault()
&& InstanceLocation.GetHashCode() == other.InstanceLocation.GetHashCode()
&& InstanceReferenceOperationSyntax.GetHashCodeOrDefault() == other.InstanceReferenceOperationSyntax.GetHashCodeOrDefault()
&& CaptureId.GetHashCodeOrDefault() == other.CaptureId.GetHashCodeOrDefault()
&& Type.GetHashCodeOrDefault() == other.Type.GetHashCodeOrDefault()
&& Parent.GetHashCodeOrDefault() == other.Parent.GetHashCodeOrDefault()
&& IsThisOrMeInstance.GetHashCode() == other.IsThisOrMeInstance.GetHashCode();
}
internal AnalysisEntity WithIndices(ImmutableArray<AbstractIndex> indices)
=> new(Symbol, indices, InstanceReferenceOperationSyntax, CaptureId, InstanceLocation, Type, Parent, IsThisOrMeInstance);

public bool EqualsIgnoringInstanceLocation(AnalysisEntity? other)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private void ClearOverlappingAnalysisDataForIndexedEntity(AnalysisEntity analysi
}

if (canOverlap &&
entity.EqualsIgnoringIndices(analysisEntity) &&
entity.WithIndices(analysisEntity.Indices).Equals(analysisEntity) &&
CoreAnalysisData.TryGetValue(entity, out var existingValue))
{
var mergedValue = ValueDomain.Merge(value, existingValue);
Expand Down

0 comments on commit 2a58a22

Please sign in to comment.