From a185c49a11f7c14cc406088e8b463918a67014e1 Mon Sep 17 00:00:00 2001 From: Pavel Koneski Date: Tue, 31 Mar 2026 14:57:02 -0700 Subject: [PATCH 1/3] Replace Dictionary with HashSet in NewTypeMaker --- src/core/IronPython/Runtime/Types/NewTypeMaker.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/IronPython/Runtime/Types/NewTypeMaker.cs b/src/core/IronPython/Runtime/Types/NewTypeMaker.cs index 3b19916ce..517b4bb73 100644 --- a/src/core/IronPython/Runtime/Types/NewTypeMaker.cs +++ b/src/core/IronPython/Runtime/Types/NewTypeMaker.cs @@ -274,7 +274,7 @@ private Dictionary ImplementType() { ImplementProtectedFieldAccessors(specialNames); - Dictionary doneTypes = new Dictionary(); + var doneTypes = new HashSet(); foreach (Type interfaceType in _interfaceTypes) { DoInterfaceType(interfaceType, doneTypes, specialNames); } @@ -364,15 +364,15 @@ private static bool CanOverrideMethod(MethodInfo mi) { return true; } - private void DoInterfaceType(Type interfaceType, Dictionary doneTypes, Dictionary specialNames) { + private void DoInterfaceType(Type interfaceType, HashSet doneTypes, Dictionary specialNames) { if (interfaceType == typeof(IDynamicMetaObjectProvider)) { // very tricky, we'll handle it when we're creating // our own IDynamicMetaObjectProvider interface return; } - if (doneTypes.ContainsKey(interfaceType)) return; - doneTypes.Add(interfaceType, true); + if (doneTypes.Contains(interfaceType)) return; + doneTypes.Add(interfaceType); OverrideMethods(interfaceType, specialNames); foreach (Type t in interfaceType.GetInterfaces()) { From 5e24b59a59fdd042cc73759761ef8d37b12d7e7c Mon Sep 17 00:00:00 2001 From: Pavel Koneski Date: Tue, 31 Mar 2026 15:11:00 -0700 Subject: [PATCH 2/3] Replace Dictionary with HashSet in ClassDefinition --- src/core/IronPython/Compiler/Ast/ClassDefinition.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/IronPython/Compiler/Ast/ClassDefinition.cs b/src/core/IronPython/Compiler/Ast/ClassDefinition.cs index 8c68fab0b..e3f36de40 100644 --- a/src/core/IronPython/Compiler/Ast/ClassDefinition.cs +++ b/src/core/IronPython/Compiler/Ast/ClassDefinition.cs @@ -407,10 +407,10 @@ public static string[] FindNames(FunctionDefinition function) { var finder = new SelfNameFinder(function, parameters[0]); function.Body.Walk(finder); - return ArrayUtils.ToArray(finder._names.Keys); + return [..finder._names]; } - private readonly Dictionary _names = new Dictionary(StringComparer.Ordinal); + private readonly HashSet _names = new(StringComparer.Ordinal); private bool IsSelfReference(Expression expr) { return expr is NameExpression ne @@ -426,7 +426,7 @@ public override bool Walk(AssignmentStatement node) { foreach (Expression lhs in node.Left) { if (lhs is MemberExpression me) { if (IsSelfReference(me.Target)) { - _names[me.Name] = true; + _names.Add(me.Name); } } } From 915c47f83b98f00178a07c6543a6bb03b4fc0982 Mon Sep 17 00:00:00 2001 From: Pavel Koneski Date: Tue, 31 Mar 2026 19:36:53 -0700 Subject: [PATCH 3/3] Replace Dictionary with HashSet in SQLite.Connection --- src/extensions/IronPython.SQLite/Connection.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/extensions/IronPython.SQLite/Connection.cs b/src/extensions/IronPython.SQLite/Connection.cs index 65e5e9361..14bd0b0b0 100644 --- a/src/extensions/IronPython.SQLite/Connection.cs +++ b/src/extensions/IronPython.SQLite/Connection.cs @@ -58,7 +58,7 @@ public string isolation_level private List statements = new List(); private int created_statements = 0; - private Dictionary function_pinboard = new Dictionary(); + private readonly HashSet function_pinboard = new(); internal Sqlite3.sqlite3 db; @@ -286,7 +286,7 @@ public void create_function(CodeContext context, string name, int narg, object f if(rc != Sqlite3.SQLITE_OK) throw MakeOperationalError("Error creating function"); else - this.function_pinboard[func] = null; + this.function_pinboard.Add(func); } private static void callUserFunction(Sqlite3.sqlite3_context ctx, int argc, sqlite3_value[] argv) @@ -459,7 +459,7 @@ public void create_aggregate(CodeContext context, string name, int n_arg, object if(rc != Sqlite3.SQLITE_OK) throw MakeOperationalError("Error creating aggregate"); else - this.function_pinboard[aggregate_class] = null; + this.function_pinboard.Add(aggregate_class); } #endregion