-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce allocations in AbstractProjectExtensionProvider.FilterExtensio…
…ns (#74112) * Reduce allocations in AbstractProjectExtensionProvider.FilterExtensions This ends up reducing allocations in the profile where I repeatedly brough up a lightbulb by about 0.7%. 1) Got rid of an Enum.ToString that happened on each filtering. Instead changed the code that reads the mef attributes to convert from string -> enum. 2) Got rid of a couple Contains calls which were allocating an enumerator 3) Got rid of some closures by using the args version of WhereAsArray and by creating a separate method to handle the CWT insertion.
- Loading branch information
Showing
4 changed files
with
62 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/Workspaces/Core/Portable/CodeFixesAndRefactorings/EnumArrayConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Immutable; | ||
|
||
namespace Microsoft.CodeAnalysis.CodeFixesAndRefactorings; | ||
|
||
internal static class EnumArrayConverter | ||
{ | ||
public static ImmutableArray<TEnum> FromStringArray<TEnum>(string[] strings) where TEnum : struct, Enum | ||
{ | ||
var enums = new FixedSizeArrayBuilder<TEnum>(strings.Length); | ||
for (var i = 0; i < strings.Length; i++) | ||
{ | ||
var s = strings[i]; | ||
if (!Enum.TryParse(s, out TEnum enumValue)) | ||
enumValue = default; | ||
|
||
enums.Add(enumValue); | ||
} | ||
|
||
return enums.MoveToImmutable(); | ||
} | ||
} |