From 55f28500f09ab68064544457c0cd1c4820d6bff0 Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Sat, 17 Dec 2022 22:05:15 +0100 Subject: [PATCH] [GenArrays] Replace List<> with HashList<> & Fix duplicate entries warning when compiling (#1) * Replace List<> with HashSet<> * Fix duplicate entries warning If generated sources already exist don't add them to _outputFiles. * Address gdkchan's review comments --- Ryujinx.CustomTasks/GenerateArrays.cs | 24 ++++++++++++------- .../SyntaxWalker/ArraySizeCollector.cs | 7 +++--- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Ryujinx.CustomTasks/GenerateArrays.cs b/Ryujinx.CustomTasks/GenerateArrays.cs index d65fad3..440f284 100644 --- a/Ryujinx.CustomTasks/GenerateArrays.cs +++ b/Ryujinx.CustomTasks/GenerateArrays.cs @@ -1,12 +1,13 @@ -using Microsoft.CodeAnalysis; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.Build.Framework; +using Ryujinx.CustomTasks.Helper; +using Ryujinx.CustomTasks.SyntaxWalker; using System.Collections.Generic; using System.IO; -using Ryujinx.CustomTasks.SyntaxWalker; -using Ryujinx.CustomTasks.Helper; -using Task = Microsoft.Build.Utilities.Task; +using System.Linq; namespace Ryujinx.CustomTasks { @@ -54,8 +55,16 @@ namespace Ryujinx.CustomTasks private void AddGeneratedSource(string filePath, string content) { + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + else + { + _outputFiles.Add(filePath); + } + File.WriteAllText(filePath, content); - _outputFiles.Add(filePath); } private ICollection GetArraySizes(string itemPath) @@ -173,9 +182,6 @@ namespace Ryujinx.CustomTasks string arraysFilePath = Path.Combine(OutputPath, ArraysFileName); List arraySizes = new List(); - File.Delete(interfaceFilePath); - File.Delete(arraysFilePath); - foreach (var item in InputFiles) { string fullPath = item.GetMetadata("FullPath"); diff --git a/Ryujinx.CustomTasks/SyntaxWalker/ArraySizeCollector.cs b/Ryujinx.CustomTasks/SyntaxWalker/ArraySizeCollector.cs index 5882bbe..1205c61 100644 --- a/Ryujinx.CustomTasks/SyntaxWalker/ArraySizeCollector.cs +++ b/Ryujinx.CustomTasks/SyntaxWalker/ArraySizeCollector.cs @@ -6,7 +6,8 @@ namespace Ryujinx.CustomTasks.SyntaxWalker { class ArraySizeCollector : CSharpSyntaxWalker { - public ICollection ArraySizes { get; } = new List(); + private readonly HashSet _arraySizes = new HashSet(); + public ICollection ArraySizes => _arraySizes; private void AddArrayString(string name) { @@ -17,9 +18,9 @@ namespace Ryujinx.CustomTasks.SyntaxWalker string rawArrayType = name.Split('<')[0]; - if (int.TryParse(rawArrayType.Substring(5), out int size) && !ArraySizes.Contains(size)) + if (int.TryParse(rawArrayType.Substring(5), out int size)) { - ArraySizes.Add(size); + _arraySizes.Add(size); } }