Skip to content
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

Small allocation optimization in StateTable.Builder.ToImmutable #72364

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Linq;
using System.Text;
using Microsoft.CodeAnalysis.Collections;
using Microsoft.CodeAnalysis.PooledObjects;

namespace Microsoft.CodeAnalysis
{
Expand Down Expand Up @@ -51,10 +52,15 @@ public sealed class Builder
public StateTableStore ToImmutable()
{
// we can cache the tables at this point, as we'll no longer be using them to determine current state
var keys = _tableBuilder.Keys.ToArray();
ToddGrun marked this conversation as resolved.
Show resolved Hide resolved
foreach (var key in keys)
var scratch = ArrayBuilder<KeyValuePair<object, IStateTable>>.GetInstance(_tableBuilder.Keys.Count);
foreach (var kvp in _tableBuilder)
{
_tableBuilder[key] = _tableBuilder[key].AsCached();
scratch.Add(kvp);
ToddGrun marked this conversation as resolved.
Show resolved Hide resolved
}

foreach (var kvp in scratch)
{
_tableBuilder[kvp.Key] = kvp.Value.AsCached();
ToddGrun marked this conversation as resolved.
Show resolved Hide resolved
}

return new StateTableStore(_tableBuilder.ToImmutable());
Expand Down
Loading