[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
This commit is contained in:
TSRBerry 2022-12-17 22:05:15 +01:00 committed by GitHub
parent ed48dfcab6
commit 55f28500f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 12 deletions

View File

@ -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<int> GetArraySizes(string itemPath)
@ -173,9 +182,6 @@ namespace Ryujinx.CustomTasks
string arraysFilePath = Path.Combine(OutputPath, ArraysFileName);
List<int> arraySizes = new List<int>();
File.Delete(interfaceFilePath);
File.Delete(arraysFilePath);
foreach (var item in InputFiles)
{
string fullPath = item.GetMetadata("FullPath");

View File

@ -6,7 +6,8 @@ namespace Ryujinx.CustomTasks.SyntaxWalker
{
class ArraySizeCollector : CSharpSyntaxWalker
{
public ICollection<int> ArraySizes { get; } = new List<int>();
private readonly HashSet<int> _arraySizes = new HashSet<int>();
public ICollection<int> 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);
}
}