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); } } } 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()) { 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