Skip to content

Commit 8b3b7fb

Browse files
Improve XmlDependencies.IsDependenciesFile performance
This simpler string manipulation checks the same logic as before but much faster in the context of a large project. If the OnPostprocessAllAssets callback is invoked multiple times with thousands of files, as can happen with non-trivial Unity projects, the regex call becomes quite expensive. For profiling data see: googlesamples#601
1 parent 85fa4e7 commit 8b3b7fb

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

source/AndroidResolver/src/XmlDependencies.cs

+3-7
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,9 @@ internal class XmlDependencies {
4646
/// </summary>
4747
/// <param name="filename"></param>
4848
/// <returns>true if it is a match, false otherwise.</returns>
49-
internal bool IsDependenciesFile(string filename) {
50-
foreach (var regex in fileRegularExpressions) {
51-
if (regex.Match(filename).Success) {
52-
return true;
53-
}
54-
}
55-
return false;
49+
internal static bool IsDependenciesFile(string filename) {
50+
bool isInEditorFolder = filename.Contains("/Editor/") || filename.Contains(@"\Editor\");
51+
return isInEditorFolder && filename.EndsWith("Dependencies.xml");
5652
}
5753

5854
/// <summary>

source/AndroidResolverTests/XmlDependenciesTests.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ public class XmlDependenciesTests
1616
[TestCase("Assets/MyEditorCode/SomeDependencies.xml")]
1717
[TestCase("Assets/Editor/")]
1818
[TestCase("Assets/Editor/Dependendencies")]
19-
public void Test1(string path) {
20-
var dependencies = new XmlDependencies();
21-
bool actualResult = dependencies.IsDependenciesFile(path);
19+
public void IsDependenciesFileReturnsExpected(string path) {
20+
bool actualResult = XmlDependencies.IsDependenciesFile(path);
2221

2322
// This logic was part of the previous unoptimized implementation and can act as a test reference.
2423
bool expectedResult = Regex.IsMatch(input: path, pattern: @".*[/\\]Editor[/\\].*Dependencies\.xml$");

0 commit comments

Comments
 (0)