Skip to content

Commit a1439fc

Browse files
#136 Insufficient performance 3
1 parent 2cb649f commit a1439fc

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/Pure.DI.Core/Core/Code/VarsMap.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ReSharper disable ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator
1+
// ReSharper disable ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator
22
namespace Pure.DI.Core.Code;
33

44
/// <summary>
@@ -216,6 +216,15 @@ private void RemoveNewNonPersistentVars(Var var, IReadOnlyDictionary<int, VarSta
216216
#if DEBUG
217217
lines.AppendLine($"// remove new non-persistent vars ({reason} {var.Declaration.Name})");
218218
#endif
219+
var currentBindingId = var.AbstractNode.BindingId;
220+
var noNewItems =
221+
(_map.Count == state.Count && !_map.ContainsKey(currentBindingId))
222+
|| (_map.Count == state.Count + 1 && _map.ContainsKey(currentBindingId));
223+
if (noNewItems)
224+
{
225+
return;
226+
}
227+
219228
var newItems = new List<KeyValuePair<int, Var>>();
220229
foreach (var item in _map)
221230
{
@@ -294,6 +303,14 @@ private void RestoreState(Var var, IReadOnlyDictionary<int, VarState> state, Lin
294303

295304
// Find variables that were NOT in the snapshot (newly discovered in the nested scope),
296305
// and reset their path-specific state to defaults.
306+
var noNewItems =
307+
(_map.Count == state.Count && !_map.ContainsKey(excludeBindingId))
308+
|| (_map.Count == state.Count + 1 && _map.ContainsKey(excludeBindingId));
309+
if (noNewItems)
310+
{
311+
return;
312+
}
313+
297314
foreach (var item in _map)
298315
{
299316
if (state.ContainsKey(item.Key))

0 commit comments

Comments
 (0)