From e9b7336146727de6889b00f1f43d81d1d69a3b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Wed, 21 Aug 2024 17:36:27 +0800 Subject: [PATCH] perf : optimize asset bundle builder --- .../Editor/AssetBundleBuilder/BuildBundleInfo.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs index d009ec5a..994bae9f 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs @@ -56,6 +56,7 @@ namespace YooAsset.Editor public string EncryptedFilePath { set; get; } #endregion + private readonly HashSet _assetPaths = new HashSet(1000); /// /// 参与构建的资源列表 @@ -84,9 +85,11 @@ namespace YooAsset.Editor /// public void PackAsset(BuildAssetInfo buildAsset) { - if (IsContainsAsset(buildAsset.AssetInfo.AssetPath)) - throw new System.Exception($"Should never get here ! Asset is existed : {buildAsset.AssetInfo.AssetPath}"); + string assetPath = buildAsset.AssetInfo.AssetPath; + if (_assetPaths.Contains(assetPath)) + throw new System.Exception($"Should never get here ! Asset is existed : {assetPath}"); + _assetPaths.Add(assetPath); MainAssets.Add(buildAsset); } @@ -95,14 +98,7 @@ namespace YooAsset.Editor /// public bool IsContainsAsset(string assetPath) { - foreach (var buildAsset in MainAssets) - { - if (buildAsset.AssetInfo.AssetPath == assetPath) - { - return true; - } - } - return false; + return _assetPaths.Contains(assetPath); } ///