Skip to content

Commit 914002a

Browse files
authored
Replace Dictionary with HashSet (#2033)
* Replace Dictionary with HashSet in NewTypeMaker * Replace Dictionary with HashSet in ClassDefinition * Replace Dictionary with HashSet in SQLite.Connection
1 parent 14ecb62 commit 914002a

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/core/IronPython/Compiler/Ast/ClassDefinition.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,10 @@ public static string[] FindNames(FunctionDefinition function) {
407407

408408
var finder = new SelfNameFinder(function, parameters[0]);
409409
function.Body.Walk(finder);
410-
return ArrayUtils.ToArray(finder._names.Keys);
410+
return [..finder._names];
411411
}
412412

413-
private readonly Dictionary<string, bool> _names = new Dictionary<string, bool>(StringComparer.Ordinal);
413+
private readonly HashSet<string> _names = new(StringComparer.Ordinal);
414414

415415
private bool IsSelfReference(Expression expr) {
416416
return expr is NameExpression ne
@@ -426,7 +426,7 @@ public override bool Walk(AssignmentStatement node) {
426426
foreach (Expression lhs in node.Left) {
427427
if (lhs is MemberExpression me) {
428428
if (IsSelfReference(me.Target)) {
429-
_names[me.Name] = true;
429+
_names.Add(me.Name);
430430
}
431431
}
432432
}

src/core/IronPython/Runtime/Types/NewTypeMaker.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ private Dictionary<string, string[]> ImplementType() {
274274

275275
ImplementProtectedFieldAccessors(specialNames);
276276

277-
Dictionary<Type, bool> doneTypes = new Dictionary<Type, bool>();
277+
var doneTypes = new HashSet<Type>();
278278
foreach (Type interfaceType in _interfaceTypes) {
279279
DoInterfaceType(interfaceType, doneTypes, specialNames);
280280
}
@@ -364,15 +364,15 @@ private static bool CanOverrideMethod(MethodInfo mi) {
364364
return true;
365365
}
366366

367-
private void DoInterfaceType(Type interfaceType, Dictionary<Type, bool> doneTypes, Dictionary<string, string[]> specialNames) {
367+
private void DoInterfaceType(Type interfaceType, HashSet<Type> doneTypes, Dictionary<string, string[]> specialNames) {
368368
if (interfaceType == typeof(IDynamicMetaObjectProvider)) {
369369
// very tricky, we'll handle it when we're creating
370370
// our own IDynamicMetaObjectProvider interface
371371
return;
372372
}
373373

374-
if (doneTypes.ContainsKey(interfaceType)) return;
375-
doneTypes.Add(interfaceType, true);
374+
if (doneTypes.Contains(interfaceType)) return;
375+
doneTypes.Add(interfaceType);
376376
OverrideMethods(interfaceType, specialNames);
377377

378378
foreach (Type t in interfaceType.GetInterfaces()) {

src/extensions/IronPython.SQLite/Connection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public string isolation_level
5858
private List<WeakReference> statements = new List<WeakReference>();
5959
private int created_statements = 0;
6060

61-
private Dictionary<object, object> function_pinboard = new Dictionary<object, object>();
61+
private readonly HashSet<object> function_pinboard = new();
6262

6363
internal Sqlite3.sqlite3 db;
6464

@@ -286,7 +286,7 @@ public void create_function(CodeContext context, string name, int narg, object f
286286
if(rc != Sqlite3.SQLITE_OK)
287287
throw MakeOperationalError("Error creating function");
288288
else
289-
this.function_pinboard[func] = null;
289+
this.function_pinboard.Add(func);
290290
}
291291

292292
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
459459
if(rc != Sqlite3.SQLITE_OK)
460460
throw MakeOperationalError("Error creating aggregate");
461461
else
462-
this.function_pinboard[aggregate_class] = null;
462+
this.function_pinboard.Add(aggregate_class);
463463
}
464464

465465
#endregion

0 commit comments

Comments
 (0)