diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/TreeWalkProgress.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/TreeWalkProgress.cs index fa08a5dce92..655ac766247 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/TreeWalkProgress.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/TreeWalkProgress.cs @@ -1,51 +1,29 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -/*++ - - Abstract: - This file implements the TreeWalkProgress - used by the Xps Serialization APIs for tracking cycles in a visual tree. ---*/ using System.Windows.Media; -namespace System.Windows.Xps.Serialization +namespace System.Windows.Xps.Serialization; + +/// +/// This class is used by the Xps Serialization APIs for tracking cycles in a visual tree. +/// +internal sealed class TreeWalkProgress { - /// - /// This class is used by the Xps Serialization APIs for tracking cycles in a visual tree. - /// - internal class TreeWalkProgress - { - public bool EnterTreeWalk(ICyclicBrush brush) - { - if(this._cyclicBrushes.ContainsKey(brush)) - { - return false; - } - - this._cyclicBrushes.Add(brush, EmptyStruct.Default); - return true; - } - - public void ExitTreeWalk(ICyclicBrush brush) - { - this._cyclicBrushes.Remove(brush); - } - - public bool IsTreeWalkInProgress(ICyclicBrush brush) - { - return this._cyclicBrushes.ContainsKey(brush); - } - - // We use the keys of this dictionary to simulate a set - // We do not use HashSet to avoid a perf regression by loading System.Core.dll - // It also makes the fix easier to backport to pre .net 3.5 releases - private IDictionary _cyclicBrushes = new Dictionary(); - - // A struct that when optimized does not consume per instance heap\stack space - private struct EmptyStruct - { - public static EmptyStruct Default = new EmptyStruct(); - } + private readonly HashSet _cyclicBrushes = new(); + + public bool EnterTreeWalk(ICyclicBrush brush) + { + return _cyclicBrushes.Add(brush); + } + + public void ExitTreeWalk(ICyclicBrush brush) + { + _cyclicBrushes.Remove(brush); + } + + public bool IsTreeWalkInProgress(ICyclicBrush brush) + { + return _cyclicBrushes.Contains(brush); } }