diff --git a/Src/IronPython/Runtime/Binding/PythonExtensionBinder.cs b/Src/IronPython/Runtime/Binding/PythonExtensionBinder.cs index 19546f2ea..9096f0574 100644 --- a/Src/IronPython/Runtime/Binding/PythonExtensionBinder.cs +++ b/Src/IronPython/Runtime/Binding/PythonExtensionBinder.cs @@ -24,7 +24,7 @@ public PythonExtensionBinder(PythonBinder binder, ExtensionMethodSet extensionMe public override MemberGroup GetMember(MemberRequestKind actionKind, Type type, string name) { var res = base.GetMember(actionKind, type, name); if (res.Count == 0) { - List trackers = new List(); + HashSet trackers = new HashSet(); foreach (var method in _extMethodSet.GetExtensionMethods(name)) { var parameters = method.GetParameters(); @@ -35,11 +35,11 @@ public override MemberGroup GetMember(MemberRequestKind actionKind, Type type, s var paramType = parameters[0].ParameterType; if (IsApplicableExtensionMethod(type, paramType)) { - trackers.Add(MemberTracker.FromMemberInfo(method, paramType)); + (trackers ??= new HashSet()).Add(MemberTracker.FromMemberInfo(method, paramType)); } } - if (trackers.Count > 0) { + if (trackers is not null) { return new MemberGroup(trackers.ToArray()); } } diff --git a/Src/IronPython/Runtime/ExtensionMethodSet.cs b/Src/IronPython/Runtime/ExtensionMethodSet.cs index 7523007f8..8490d23ba 100644 --- a/Src/IronPython/Runtime/ExtensionMethodSet.cs +++ b/Src/IronPython/Runtime/ExtensionMethodSet.cs @@ -176,15 +176,18 @@ public IEnumerable GetExtensionMethods(string/*!*/ name) { lock (this) { EnsureLoaded(); + var yieldedMethods = new HashSet(); + foreach (var keyValue in _loadedAssemblies) { AssemblyLoadInfo info = keyValue.Value; Debug.Assert(info.Types != null); foreach (var type in info.Types) { - List methods; - if (type.ExtensionMethods.TryGetValue(name, out methods)) { + if (type.ExtensionMethods.TryGetValue(name, out var methods)) { foreach (var method in methods) { - yield return method; + if (yieldedMethods.Add(method)) { + yield return method; + } } } }