Skip to content

Commit d2e6529

Browse files
committed
Use SelectAsArray instead of LINQ
1 parent 127b538 commit d2e6529

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/Compilers/Core/Portable/InternalUtilities/EnumerableExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,10 @@ public static ImmutableArray<TResult> SelectAsArray<TSource, TResult>(this IEnum
305305
return ImmutableArray<TResult>.Empty;
306306
}
307307

308-
var builder = ArrayBuilder<TResult>.GetInstance();
308+
var builder = source is ICollection<TSource> collection
309+
? ArrayBuilder<TResult>.GetInstance(collection.Count)
310+
: ArrayBuilder<TResult>.GetInstance();
311+
309312
builder.AddRange(source.Select(selector));
310313

311314
return builder.ToImmutableAndFree();

src/Compilers/Core/Portable/InternalUtilities/OneOrMany.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public OneOrMany<TResult> Select<TResult>(Func<T, TResult> selector)
137137
{
138138
return HasOne ?
139139
OneOrMany.Create(selector(_one)) :
140-
OneOrMany.Create(_many.SelectAsArray(selector));
140+
OneOrMany.Create(Microsoft.CodeAnalysis.ImmutableArrayExtensions.SelectAsArray(_many, selector));
141141
}
142142

143143
public OneOrMany<TResult> Select<TResult, TArg>(Func<T, TArg, TResult> selector, TArg arg)

src/VisualStudio/Core/Def/Implementation/ProjectSystem/FileChangeWatcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ public async ValueTask ApplyAsync(IVsAsyncFileChangeEx service, CancellationToke
422422

423423
case Kind.UnwatchFiles:
424424
Contract.ThrowIfFalse(_tokens is not null);
425-
await service.UnadviseFileChangesAsync(_tokens.Select(token => token.Cookie!.Value).ToArray(), cancellationToken).ConfigureAwait(false);
425+
await service.UnadviseFileChangesAsync(_tokens.SelectAsArray(token => token.Cookie!.Value), cancellationToken).ConfigureAwait(false);
426426
return;
427427

428428
default:

0 commit comments

Comments
 (0)