From c9a57fc264c28da7774c02ecbb6f133e4fb5b84d Mon Sep 17 00:00:00 2001 From: Eric Arndt Date: Tue, 15 Jul 2025 14:50:26 -0700 Subject: [PATCH 1/3] Streamline BuildGlobResultFromIncludeItem --- src/Build/Definition/Project.cs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Build/Definition/Project.cs b/src/Build/Definition/Project.cs index 234edc53ea6..a98ea19592d 100644 --- a/src/Build/Definition/Project.cs +++ b/src/Build/Definition/Project.cs @@ -2624,14 +2624,28 @@ private GlobResult BuildGlobResultFromIncludeItem(ProjectItemElement itemElement { var includeItemspec = new EvaluationItemSpec(itemElement.Include, _data.Expander, itemElement.IncludeLocation, itemElement.ContainingProject.DirectoryPath); - ItemSpecFragment[] includeGlobFragments = includeItemspec.Fragments.Where(f => f is GlobFragment && f.TextFragment.AsSpan().IndexOfAny(s_invalidGlobChars) < 0).ToArray(); - if (includeGlobFragments.Length == 0) + List includeGobFragmentsList = null; + foreach (ItemSpecFragment fragment in includeItemspec.Fragments) + { + if (fragment is GlobFragment && fragment.TextFragment.AsSpan().IndexOfAny(s_invalidGlobChars) < 0) + { + includeGobFragmentsList ??= new List(includeItemspec.Fragments.Count); + includeGobFragmentsList.Add(fragment); + } + } + + if (includeGobFragmentsList == null || includeGobFragmentsList.Count == 0) { return null; } - ImmutableArray includeGlobStrings = includeGlobFragments.Select(f => f.TextFragment).ToImmutableArray(); - var includeGlob = CompositeGlob.Create(includeGlobFragments.Select(f => f.ToMSBuildGlob())); + string[] includeGlobStrings = new string[includeGobFragmentsList.Count]; + for (int i = 0; i < includeGlobStrings.Length; ++i) + { + includeGlobStrings[i] = includeGobFragmentsList[i].TextFragment; + } + + var includeGlob = CompositeGlob.Create(includeGobFragmentsList.Select(f => f.ToMSBuildGlob())); IEnumerable excludeFragmentStrings = []; IMSBuildGlob excludeGlob = null; From c2efa94e4fad18a81da28278c45c69025beb3bec Mon Sep 17 00:00:00 2001 From: Eric Arndt Date: Mon, 18 Aug 2025 10:33:50 -0700 Subject: [PATCH 2/3] Fix typo --- src/Build/Definition/Project.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Build/Definition/Project.cs b/src/Build/Definition/Project.cs index a98ea19592d..2efd217cfbd 100644 --- a/src/Build/Definition/Project.cs +++ b/src/Build/Definition/Project.cs @@ -2624,28 +2624,28 @@ private GlobResult BuildGlobResultFromIncludeItem(ProjectItemElement itemElement { var includeItemspec = new EvaluationItemSpec(itemElement.Include, _data.Expander, itemElement.IncludeLocation, itemElement.ContainingProject.DirectoryPath); - List includeGobFragmentsList = null; + List includeGlobFragmentsList = null; foreach (ItemSpecFragment fragment in includeItemspec.Fragments) { if (fragment is GlobFragment && fragment.TextFragment.AsSpan().IndexOfAny(s_invalidGlobChars) < 0) { - includeGobFragmentsList ??= new List(includeItemspec.Fragments.Count); - includeGobFragmentsList.Add(fragment); + includeGlobFragmentsList ??= new List(includeItemspec.Fragments.Count); + includeGlobFragmentsList.Add(fragment); } } - if (includeGobFragmentsList == null || includeGobFragmentsList.Count == 0) + if (includeGlobFragmentsList == null || includeGlobFragmentsList.Count == 0) { return null; } - string[] includeGlobStrings = new string[includeGobFragmentsList.Count]; + string[] includeGlobStrings = new string[includeGlobFragmentsList.Count]; for (int i = 0; i < includeGlobStrings.Length; ++i) { - includeGlobStrings[i] = includeGobFragmentsList[i].TextFragment; + includeGlobStrings[i] = includeGlobFragmentsList[i].TextFragment; } - var includeGlob = CompositeGlob.Create(includeGobFragmentsList.Select(f => f.ToMSBuildGlob())); + var includeGlob = CompositeGlob.Create(includeGlobFragmentsList.Select(f => f.ToMSBuildGlob())); IEnumerable excludeFragmentStrings = []; IMSBuildGlob excludeGlob = null; From 704980bea6427b2f64cc7dff426ec6aa4af17b2d Mon Sep 17 00:00:00 2001 From: Eric Arndt Date: Thu, 25 Sep 2025 10:51:18 -0700 Subject: [PATCH 3/3] Make immutable again --- src/Build/Definition/Project.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Build/Definition/Project.cs b/src/Build/Definition/Project.cs index 2efd217cfbd..4638632614c 100644 --- a/src/Build/Definition/Project.cs +++ b/src/Build/Definition/Project.cs @@ -2669,7 +2669,7 @@ private GlobResult BuildGlobResultFromIncludeItem(ProjectItemElement itemElement var includeGlobWithGaps = CreateIncludeGlobWithGaps(includeGlob, excludeGlob, removeGlob); - return new GlobResult(itemElement, includeGlobStrings, includeGlobWithGaps, excludeFragmentStrings, removeFragmentStrings); + return new GlobResult(itemElement, includeGlobStrings.ToImmutableArray(), includeGlobWithGaps, excludeFragmentStrings, removeFragmentStrings); } private static IMSBuildGlob CreateIncludeGlobWithGaps(IMSBuildGlob includeGlob, IMSBuildGlob excludeGlob, IMSBuildGlob removeGlob)