diff --git a/Ramstack.Globbing/Traversal/FileTreeAsyncEnumerable.cs b/Ramstack.Globbing/Traversal/FileTreeAsyncEnumerable.cs index 0f81110..0188803 100644 --- a/Ramstack.Globbing/Traversal/FileTreeAsyncEnumerable.cs +++ b/Ramstack.Globbing/Traversal/FileTreeAsyncEnumerable.cs @@ -86,10 +86,10 @@ private async IAsyncEnumerable EnumerateAsync(CancellationTokenSource? try { - var stack = new Stack<(TEntry Directory, string Path)>(); - stack.Push((_directory, "")); + var queue = new Queue<(TEntry Directory, string Path)>(); + queue.Enqueue((_directory, "")); - while (stack.TryPop(out var e)) + while (queue.TryDequeue(out var e)) { await foreach (var entry in ChildrenSelector(e.Directory, cancellationToken).ConfigureAwait(false)) { @@ -101,7 +101,7 @@ private async IAsyncEnumerable EnumerateAsync(CancellationTokenSource? if (ShouldRecursePredicate == null || ShouldRecursePredicate(entry)) if (PathHelper.IsPartialMatch(fullName, Patterns, Flags)) - stack.Push((entry, fullName.ToString())); + queue.Enqueue((entry, fullName.ToString())); if (ShouldIncludePredicate == null || ShouldIncludePredicate(entry)) if (PathHelper.IsMatch(fullName, Patterns, Flags)) diff --git a/Ramstack.Globbing/Traversal/FileTreeEnumerable.cs b/Ramstack.Globbing/Traversal/FileTreeEnumerable.cs index c54d7d4..32b94de 100644 --- a/Ramstack.Globbing/Traversal/FileTreeEnumerable.cs +++ b/Ramstack.Globbing/Traversal/FileTreeEnumerable.cs @@ -74,10 +74,10 @@ private IEnumerable Enumerate() { var chars = ArrayPool.Shared.Rent(512); - var stack = new Stack<(TEntry Directory, string Path)>(); - stack.Push((_directory, "")); + var queue = new Queue<(TEntry Directory, string Path)>(); + queue.Enqueue((_directory, "")); - while (stack.TryPop(out var e)) + while (queue.TryDequeue(out var e)) { foreach (var entry in ChildrenSelector(e.Directory)) { @@ -89,7 +89,7 @@ private IEnumerable Enumerate() if (ShouldRecursePredicate == null || ShouldRecursePredicate(entry)) if (PathHelper.IsPartialMatch(fullName, Patterns, Flags)) - stack.Push((entry, fullName.ToString())); + queue.Enqueue((entry, fullName.ToString())); if (ShouldIncludePredicate == null || ShouldIncludePredicate(entry)) if (PathHelper.IsMatch(fullName, Patterns, Flags))