From b39038008d4163818634f0f2a93f889e9c810000 Mon Sep 17 00:00:00 2001 From: Slendy Date: Sat, 23 Dec 2023 20:07:03 -0600 Subject: [PATCH] Use HashSet to store texture guids instead of List --- .../Helpers/GameResourceHelper.cs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/ProjectLighthouse.Servers.GameServer/Helpers/GameResourceHelper.cs b/ProjectLighthouse.Servers.GameServer/Helpers/GameResourceHelper.cs index ede5977b..3932724e 100644 --- a/ProjectLighthouse.Servers.GameServer/Helpers/GameResourceHelper.cs +++ b/ProjectLighthouse.Servers.GameServer/Helpers/GameResourceHelper.cs @@ -1,5 +1,4 @@ -using System.Collections.Immutable; -using LBPUnion.ProjectLighthouse.Files; +using LBPUnion.ProjectLighthouse.Files; using LBPUnion.ProjectLighthouse.Logging; using LBPUnion.ProjectLighthouse.Types.Logging; using LBPUnion.ProjectLighthouse.Types.Resources; @@ -8,11 +7,10 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers; public static class GameResourceHelper { - private static readonly ImmutableList textureGuids = ImmutableList.Empty; + private static readonly HashSet textureGuids = new(); static GameResourceHelper() { - List guids = new(); using Stream? guidStream = typeof(GameResourceHelper).Assembly.GetManifestResourceStream("LBPUnion.ProjectLighthouse.Servers.GameServer.textureGuids.txt"); if (guidStream == null) { @@ -26,21 +24,17 @@ public static class GameResourceHelper string? guid = reader.ReadLine(); if (guid == null) continue; - guids.Add(guid); + textureGuids.Add(guid); } - textureGuids = ImmutableList.Create(guids.ToArray()); } public static bool IsValidTexture(string resource) { if (!FileHelper.IsResourceValid(resource)) return false; - if (resource.StartsWith("g")) - { - return textureGuids.Contains(resource[1..]); - } + if (resource.StartsWith("g")) return textureGuids.Contains(resource[1..]); - return LbpFile.FromHash(resource)?.FileType is LbpFileType.Png or LbpFileType.Jpeg or LbpFileType.Plan - or LbpFileType.Painting or LbpFileType.Texture; + return LbpFile.FromHash(resource)?.FileType is LbpFileType.Png or LbpFileType.Jpeg or LbpFileType.Painting + or LbpFileType.Texture; } } \ No newline at end of file