-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce allocations in AbstractProjectExtensionProvider.FilterExtensions #74112
Changes from 6 commits
3f5dda5
79da719
6f15ab7
2d6cec6
a4ca4dd
281606c
319ad3e
8599bae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -989,7 +989,11 @@ private ImmutableDictionary<DiagnosticId, ImmutableArray<CodeFixProvider>> Compu | |
} | ||
|
||
private static ProjectCodeFixProvider.ExtensionInfo GetExtensionInfo(ExportCodeFixProviderAttribute attribute) | ||
=> new(attribute.DocumentKinds, attribute.DocumentExtensions); | ||
{ | ||
var kinds = EnumArrayConverter.FromStringArray<TextDocumentKind>(attribute.DocumentKinds); | ||
|
||
return new(kinds, attribute.DocumentExtensions); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we not have a helper for this? (since it seems duplicated). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
|
||
private sealed class FixerComparer : IComparer<CodeFixProvider> | ||
{ | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,28 @@ | ||||||
// 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; | ||||||
|
||||||
namespace Microsoft.CodeAnalysis.CodeFixesAndRefactorings; | ||||||
|
||||||
internal class EnumArrayConverter | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
public static TEnum[] FromStringArray<TEnum>(string[] strings) where TEnum : struct | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nite: consider returning ImmutableArray instread if you don't need to mutate hte array. |
||||||
{ | ||||||
if (!typeof(TEnum).IsEnum) | ||||||
throw new ArgumentException("T must be an enumerated type"); | ||||||
|
||||||
var enums = new TEnum[strings.Length]; | ||||||
for (var i = 0; i < enums.Length; i++) | ||||||
{ | ||||||
var s = strings[i]; | ||||||
if (!Enum.TryParse(s, out TEnum enumValue)) | ||||||
enumValue = default; | ||||||
|
||||||
enums[i] = enumValue; | ||||||
} | ||||||
|
||||||
return enums; | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i have no problem with you inlining this method into WhereAsArray.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried it, stared at it for a minute, and I personally like it better in the current form. Will gladly change it though if you feel fairly strongly or have an objective reason.