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 all commits
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 @@ -2,11 +2,7 @@
// 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.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using Microsoft.CodeAnalysis.Collections;

namespace Microsoft.CodeAnalysis
Expand Down Expand Up @@ -51,10 +47,13 @@ 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)
foreach (var kvp in _tableBuilder)
{
_tableBuilder[key] = _tableBuilder[key].AsCached();
var cachedValue = kvp.Value.AsCached();
if (cachedValue != kvp.Value)
{
SegmentedCollectionsMarshal.GetValueRefOrNullRef(_tableBuilder, kvp.Key) = cachedValue;
}
}

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