Skip to content

Commit

Permalink
Make method
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed May 8, 2024
1 parent da8d776 commit e035fc7
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection.Metadata;
using System.Threading;
Expand Down Expand Up @@ -37,6 +38,12 @@ private static bool TryGetAnalyzerImageReferenceGuid(AnalyzerImageReference imag
return s_analyzerImageReferenceMap.TryGetValue(imageReference, out guid);
}

private static bool TryGetAnalyzerImageReferenceFromGuid(Guid guid, [NotNullWhen(true)] out AnalyzerImageReference? imageReference)
{
lock (s_analyzerImageReferenceMapGate)
return s_analyzerImageReferenceMap.TryGetKey(guid, out imageReference);
}

public static Checksum CreateChecksum(MetadataReference reference, CancellationToken cancellationToken)
{
if (reference is PortableExecutableReference portable)
Expand Down Expand Up @@ -145,11 +152,8 @@ public virtual AnalyzerReference ReadAnalyzerReferenceFrom(ObjectReader reader,

case nameof(AnalyzerImageReference):
var guid = reader.ReadGuid();
lock (s_analyzerImageReferenceMapGate)
{
Contract.ThrowIfFalse(s_analyzerImageReferenceMap.TryGetKey(guid, out var analyzerImageReference));
return analyzerImageReference;
}
Contract.ThrowIfFalse(TryGetAnalyzerImageReferenceFromGuid(guid, out var analyzerImageReference));
return analyzerImageReference;
}

throw ExceptionUtilities.UnexpectedValue(type);
Expand Down

0 comments on commit e035fc7

Please sign in to comment.