diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/TreeWalkProgress.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/TreeWalkProgress.cs
index cb6a90c77..1bd91cac1 100644
--- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/TreeWalkProgress.cs
+++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/TreeWalkProgress.cs
@@ -2,60 +2,30 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-/*++
-
- Abstract:
- This file implements the TreeWalkProgress
- used by the Xps Serialization APIs for tracking cycles in a visual tree.
---*/
-using System;
-using System.Collections;
-using System.Collections.Specialized;
using System.Collections.Generic;
-using System.ComponentModel;
-using System.IO;
-using System.Text;
using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Xps.Packaging;
-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);
}
}