Skip to content

refactor: use Array.Empty #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Glob/PathTraverser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
Expand All @@ -15,7 +16,7 @@ public static IEnumerable<FileSystemInfo> Traverse(this DirectoryInfo root, stri

var cache = new TraverseOptions(caseSensitive, emitFiles, emitDirectories);

return segments.Length == 0 ? new FileSystemInfo[0] : Traverse(root, segments, cache);
return segments.Length == 0 ? Array.Empty<FileSystemInfo>() : Traverse(root, segments, cache);
}

internal static IEnumerable<FileSystemInfo> Traverse(DirectoryInfo root, Segment[] segments, TraverseOptions options) =>
Expand Down
7 changes: 4 additions & 3 deletions src/Glob/PathTraverserEnumerable.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -12,8 +13,8 @@ internal class PathTraverserEnumerable : IEnumerable<FileSystemInfo>
private readonly Segment[] _segments;
private readonly TraverseOptions _options;

private static readonly FileSystemInfo[] _emptyFileSystemInfoArray = new FileSystemInfo[0];
private static readonly DirectoryInfo[] _emptyPathJobArray = new DirectoryInfo[0];
private static readonly FileSystemInfo[] _emptyFileSystemInfoArray = Array.Empty<FileSystemInfo>();
private static readonly DirectoryInfo[] _emptyPathJobArray = Array.Empty<DirectoryInfo>();
public PathTraverserEnumerable(List<DirectoryInfo> roots, Segment[] segments, TraverseOptions options)
{
this._originalRoots = roots;
Expand Down
7 changes: 4 additions & 3 deletions src/Glob/TraverseOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;

namespace GlobExpressions
Expand All @@ -19,8 +20,8 @@ public TraverseOptions(bool caseSensitive, bool emitFiles, bool emitDirectories)
public bool EmitFiles { get; }
public bool EmitDirectories { get; }

private static readonly FileInfo[] _emptyFileInfos = new FileInfo[0];
private static readonly DirectoryInfo[] _emptyDirectoryInfos = new DirectoryInfo[0];
private static readonly FileInfo[] _emptyFileInfos = Array.Empty<FileInfo>();
private static readonly DirectoryInfo[] _emptyDirectoryInfos = Array.Empty<DirectoryInfo>();

public virtual FileInfo[] GetFiles(DirectoryInfo root)
{
Expand Down
5 changes: 3 additions & 2 deletions test/Glob.Tests/MockTraverseOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections;
using System;
using System.Collections;
using System.IO;
using System.IO.Abstractions;
using System.IO.Abstractions.TestingHelpers;
Expand Down Expand Up @@ -31,7 +32,7 @@ public override DirectoryInfo[] GetDirectories(DirectoryInfo root)
// fake enumerator
public IEnumerator GetEnumerator()
{
return new int[0].GetEnumerator();
return Array.Empty<int>().GetEnumerator();
}

public void Add(string path)
Expand Down