1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-11 13:10:58 +00:00

Use Array.Empty instead of allocating a every time

Use `System.Array.Empty<T>` to get an empty array instead of allocating
a new one every time. Since arrays are immutable there is no need to
allocate them every time.
This commit is contained in:
Raul Santos
2021-07-25 13:46:31 +02:00
parent 8932b55011
commit accd05f4ad
4 changed files with 31 additions and 21 deletions

View File

@@ -74,10 +74,10 @@ namespace GodotTools.Utils
}
private static readonly IEnumerable<string> LinuxBSDPlatforms =
new[] {Names.Linux, Names.FreeBSD, Names.NetBSD, Names.BSD};
new[] { Names.Linux, Names.FreeBSD, Names.NetBSD, Names.BSD };
private static readonly IEnumerable<string> UnixLikePlatforms =
new[] {Names.MacOS, Names.Server, Names.Haiku, Names.Android, Names.iOS}
new[] { Names.MacOS, Names.Server, Names.Haiku, Names.Android, Names.iOS }
.Concat(LinuxBSDPlatforms).ToArray();
private static readonly Lazy<bool> _isWindows = new Lazy<bool>(() => IsOS(Names.Windows));
@@ -111,7 +111,7 @@ namespace GodotTools.Utils
private static string PathWhichWindows([NotNull] string name)
{
string[] windowsExts = Environment.GetEnvironmentVariable("PATHEXT")?.Split(PathSep) ?? new string[] { };
string[] windowsExts = Environment.GetEnvironmentVariable("PATHEXT")?.Split(PathSep) ?? Array.Empty<string>();
string[] pathDirs = Environment.GetEnvironmentVariable("PATH")?.Split(PathSep);
var searchDirs = new List<string>();
@@ -128,10 +128,10 @@ namespace GodotTools.Utils
return searchDirs.Select(dir => Path.Combine(dir, name)).FirstOrDefault(File.Exists);
return (from dir in searchDirs
select Path.Combine(dir, name)
select Path.Combine(dir, name)
into path
from ext in windowsExts
select path + ext).FirstOrDefault(File.Exists);
from ext in windowsExts
select path + ext).FirstOrDefault(File.Exists);
}
private static string PathWhichUnix([NotNull] string name)
@@ -196,7 +196,7 @@ namespace GodotTools.Utils
startInfo.UseShellExecute = false;
using (var process = new Process {StartInfo = startInfo})
using (var process = new Process { StartInfo = startInfo })
{
process.Start();
process.WaitForExit();