From 74acaa2216f16c79e73ac9a4848842d9d9d4e0af Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Wed, 23 Aug 2023 12:38:21 +1000 Subject: [PATCH] Cache repo root path Avoids doing file system operations multiple times during test runs. --- .../Utilities/RepoUtil.cs | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tests/Microsoft.VisualStudio.ProjectSystem.Managed.UnitTests/Utilities/RepoUtil.cs b/tests/Microsoft.VisualStudio.ProjectSystem.Managed.UnitTests/Utilities/RepoUtil.cs index abcfa786a8d..07b9658cc75 100644 --- a/tests/Microsoft.VisualStudio.ProjectSystem.Managed.UnitTests/Utilities/RepoUtil.cs +++ b/tests/Microsoft.VisualStudio.ProjectSystem.Managed.UnitTests/Utilities/RepoUtil.cs @@ -4,6 +4,8 @@ namespace Microsoft.VisualStudio.Utilities { internal static class RepoUtil { + private static string? _root; + /// /// Gets the absolute path to the checked out location of this repo. /// @@ -12,18 +14,22 @@ internal static class RepoUtil /// public static string FindRepoRootPath() { - // Start with this DLL's location - string path = typeof(RepoUtil).Assembly.Location; - - // Walk up the tree until we find the 'artifacts' folder - while (!Path.GetFileName(path).Equals("artifacts", StringComparisons.Paths)) + if (_root is null) { - path = Path.GetDirectoryName(path); + // Start with this DLL's location + string path = typeof(RepoUtil).Assembly.Location; + + // Walk up the tree until we find the 'artifacts' folder + while (!Path.GetFileName(path).Equals("artifacts", StringComparisons.Paths)) + { + path = Path.GetDirectoryName(path); + } + + // Go up one more level + _root = Path.GetDirectoryName(path); } - // Go up one more level - path = Path.GetDirectoryName(path); - return path; + return _root; } } }