-
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
Experiment with array creation. (part2) #73005
Changes from all commits
becb0c5
df92e11
5875b5a
608afd9
338facc
a2351ac
bf88bf2
23d2beb
c4f733b
c7c148a
9db2644
c8c58dd
49a00d1
a5bb571
a45c91c
4db8848
56399c2
2b62e27
ee1e680
34f78e3
4edfaf4
96b3322
5958326
761663d
7e04145
d4dbced
e8ff1a6
7709282
c55b63e
977bceb
207ea49
e0a62fd
85cbded
1b76e1f
e2e8fdb
68ec52d
b76289b
55a16c4
4b12ae8
818edfb
f74c9f4
43ec1cd
b1e7f9b
07b7123
626306d
a9536ff
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 |
---|---|---|
|
@@ -205,7 +205,7 @@ private static ExpressionSyntax GenerateTupleDeclaration(ITypeSymbol typeSymbol, | |
|
||
return TupleExpression( | ||
OpenParenToken.WithTrailingTrivia(), | ||
SeparatedList(builder.ToImmutable(), separatorBuilder.ToImmutableAndFree()), | ||
SeparatedList(builder, separatorBuilder), | ||
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. this guy doesn't need to realize the immutable arrays. so this can stay nicely as ArrayBuilders. |
||
CloseParenToken) | ||
.WithTrailingTrivia(parensDesignation.GetTrailingTrivia()); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
using Microsoft.CodeAnalysis.Formatting; | ||
using Microsoft.CodeAnalysis.LanguageService; | ||
using Microsoft.CodeAnalysis.PooledObjects; | ||
using Microsoft.CodeAnalysis.Shared.Collections; | ||
using Microsoft.CodeAnalysis.Shared.Extensions; | ||
using Roslyn.Utilities; | ||
|
||
|
@@ -244,7 +245,7 @@ private void RegisterFixForMethodOverloads( | |
|
||
ImmutableArray<CodeAction> NestByOverload() | ||
{ | ||
using var _ = ArrayBuilder<CodeAction>.GetInstance(codeFixData.Length, out var builder); | ||
var builder = new FixedSizeArrayBuilder<CodeAction>(codeFixData.Length); | ||
foreach (var data in codeFixData) | ||
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. note: all loops were audited to make sure they always add an item for each input iterated over. loops that did not do this were not updated. |
||
{ | ||
// We create the mandatory data.CreateChangedSolutionNonCascading fix first. | ||
|
@@ -276,12 +277,12 @@ ImmutableArray<CodeAction> NestByOverload() | |
builder.Add(codeAction); | ||
} | ||
|
||
return builder.ToImmutableAndClear(); | ||
return builder.MoveToImmutable(); | ||
} | ||
|
||
ImmutableArray<CodeAction> NestByCascading() | ||
{ | ||
using var _ = ArrayBuilder<CodeAction>.GetInstance(capacity: 2, out var builder); | ||
using var builder = TemporaryArray<CodeAction>.Empty; | ||
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. tiny array cases could just use temporaryarray. this guy is then cancellation-safe. teh values are placed on the stack, and copied at the end. since this is only for <4 element cases, this is basically free. |
||
|
||
var nonCascadingActions = codeFixData.SelectAsArray(data => | ||
{ | ||
|
@@ -312,7 +313,7 @@ ImmutableArray<CodeAction> NestByCascading() | |
builder.Add(CodeAction.Create(nestedCascadingTitle, cascadingActions, isInlinable: false)); | ||
} | ||
|
||
return builder.ToImmutable(); | ||
return builder.ToImmutableAndClear(); | ||
} | ||
} | ||
|
||
|
@@ -321,7 +322,7 @@ private ImmutableArray<CodeFixData> PrepareCreationOfCodeActions( | |
SeparatedSyntaxList<TArgumentSyntax> arguments, | ||
ImmutableArray<ArgumentInsertPositionData<TArgumentSyntax>> methodsAndArgumentsToAdd) | ||
{ | ||
using var _ = ArrayBuilder<CodeFixData>.GetInstance(methodsAndArgumentsToAdd.Length, out var builder); | ||
var builder = new FixedSizeArrayBuilder<CodeFixData>(methodsAndArgumentsToAdd.Length); | ||
|
||
// Order by the furthest argument index to the nearest argument index. The ones with | ||
// larger argument indexes mean that we matched more earlier arguments (and thus are | ||
|
@@ -343,7 +344,7 @@ private ImmutableArray<CodeFixData> PrepareCreationOfCodeActions( | |
builder.Add(codeFixData); | ||
} | ||
|
||
return builder.ToImmutable(); | ||
return builder.MoveToImmutable(); | ||
} | ||
|
||
private static string GetCodeFixTitle(string resourceString, IMethodSymbol methodToUpdate, bool includeParameters) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,11 +36,7 @@ public static ImmutableArray<ISymbol> GetDelegatableMembers( | |
|
||
var parameters = GetNonCapturedPrimaryConstructorParameters(fields, properties); | ||
|
||
using var _1 = ArrayBuilder<ISymbol>.GetInstance(fields.Length + properties.Length + parameters.Length, out var result); | ||
result.AddRange(fields); | ||
result.AddRange(properties); | ||
result.AddRange(parameters); | ||
return result.ToImmutableAndClear(); | ||
return [.. fields, .. properties, .. parameters]; | ||
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. much nicer :) |
||
|
||
ImmutableArray<IParameterSymbol> GetNonCapturedPrimaryConstructorParameters( | ||
ImmutableArray<IFieldSymbol> fields, | ||
|
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.
in some cases, i just literally fixed things up to avoid any builders whatsoever