Skip to content

Commit c584373

Browse files
authored
Merge pull request #69 from CeejayZSmith/perf/use-hashshet-for-dependencies
Optimize DependentObjectBasedAssetFilter by Using HashSet and Avoiding Redundant Dependency Collection
2 parents a2d9006 + f85d302 commit c584373

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Assets/SmartAddresser/Editor/Core/Models/Shared/AssetGroups/AssetFilterImpl/DependentObjectBasedAssetFilter.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public sealed class DependentObjectBasedAssetFilter : AssetFilterBase
2020
[SerializeField] private bool _onlyDirectDependencies;
2121
[SerializeField] private ObjectListableProperty _object = new ObjectListableProperty();
2222

23-
private List<string> _dependentAssetPaths = new List<string>();
23+
private HashSet<string> _dependentAssetPaths = new HashSet<string>();
2424
private bool _hasNullObject;
2525

2626
/// <summary>
@@ -50,11 +50,19 @@ public override void SetupForMatching()
5050
}
5151

5252
var path = AssetDatabase.GetAssetPath(obj);
53+
54+
// If we already have all the dependencies of 'path', we can skip
55+
if (!_onlyDirectDependencies && _dependentAssetPaths.Contains(path) == true)
56+
{
57+
continue;
58+
}
59+
5360
var dependencies = AssetDatabase.GetDependencies(path, !_onlyDirectDependencies);
54-
_dependentAssetPaths.AddRange(dependencies);
61+
foreach (var dependency in dependencies)
62+
{
63+
_dependentAssetPaths.Add(dependency);
64+
}
5565
}
56-
57-
_dependentAssetPaths = _dependentAssetPaths.Distinct().ToList();
5866
}
5967

6068
public override bool Validate(out AssetFilterValidationError error)

0 commit comments

Comments
 (0)