Skip to content

Commit

Permalink
Merge branch 'master' into feature/sa1648-static-abstract-interface-m…
Browse files Browse the repository at this point in the history
…embers
  • Loading branch information
bjornhellander committed Oct 18, 2023
2 parents 72cdc5b + 1dd5ced commit b69d4f5
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LightupHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,13 @@ internal static bool CanWrapObject(object obj, Type underlyingType)
return false;
}

ConcurrentDictionary<Type, bool> wrappedObject = SupportedObjectWrappers.GetOrAdd(underlyingType, _ => new ConcurrentDictionary<Type, bool>());
ConcurrentDictionary<Type, bool> wrappedObject = SupportedObjectWrappers.GetOrAdd(underlyingType, static _ => new ConcurrentDictionary<Type, bool>());

// Avoid creating the delegate if the value already exists
bool canCast;
if (!wrappedObject.TryGetValue(obj.GetType(), out canCast))
// Avoid creating a delegate and capture class
if (!wrappedObject.TryGetValue(obj.GetType(), out var canCast))
{
canCast = wrappedObject.GetOrAdd(
obj.GetType(),
kind => underlyingType.GetTypeInfo().IsAssignableFrom(obj.GetType().GetTypeInfo()));
canCast = underlyingType.GetTypeInfo().IsAssignableFrom(obj.GetType().GetTypeInfo());
wrappedObject.TryAdd(obj.GetType(), canCast);
}

return canCast;
Expand All @@ -93,15 +91,13 @@ internal static bool CanWrapNode(SyntaxNode node, Type underlyingType)
return false;
}

ConcurrentDictionary<SyntaxKind, bool> wrappedSyntax = SupportedSyntaxWrappers.GetOrAdd(underlyingType, _ => new ConcurrentDictionary<SyntaxKind, bool>());
ConcurrentDictionary<SyntaxKind, bool> wrappedSyntax = SupportedSyntaxWrappers.GetOrAdd(underlyingType, static _ => new ConcurrentDictionary<SyntaxKind, bool>());

// Avoid creating the delegate if the value already exists
bool canCast;
if (!wrappedSyntax.TryGetValue(node.Kind(), out canCast))
// Avoid creating a delegate and capture class
if (!wrappedSyntax.TryGetValue(node.Kind(), out var canCast))
{
canCast = wrappedSyntax.GetOrAdd(
node.Kind(),
kind => underlyingType.GetTypeInfo().IsAssignableFrom(node.GetType().GetTypeInfo()));
canCast = underlyingType.GetTypeInfo().IsAssignableFrom(node.GetType().GetTypeInfo());
wrappedSyntax.TryAdd(node.Kind(), canCast);
}

return canCast;
Expand All @@ -121,15 +117,13 @@ internal static bool CanWrapOperation(IOperation operation, Type underlyingType)
return false;
}

ConcurrentDictionary<OperationKind, bool> wrappedSyntax = SupportedOperationWrappers.GetOrAdd(underlyingType, _ => new ConcurrentDictionary<OperationKind, bool>());
ConcurrentDictionary<OperationKind, bool> wrappedSyntax = SupportedOperationWrappers.GetOrAdd(underlyingType, static _ => new ConcurrentDictionary<OperationKind, bool>());

// Avoid creating the delegate if the value already exists
bool canCast;
if (!wrappedSyntax.TryGetValue(operation.Kind, out canCast))
// Avoid creating a delegate and capture class
if (!wrappedSyntax.TryGetValue(operation.Kind, out var canCast))
{
canCast = wrappedSyntax.GetOrAdd(
operation.Kind,
kind => underlyingType.GetTypeInfo().IsAssignableFrom(operation.GetType().GetTypeInfo()));
canCast = underlyingType.GetTypeInfo().IsAssignableFrom(operation.GetType().GetTypeInfo());
wrappedSyntax.TryAdd(operation.Kind, canCast);
}

return canCast;
Expand Down

0 comments on commit b69d4f5

Please sign in to comment.