提交 a307240a 编写于 作者: C CyrusNajmabadi

Cache what symbols a serialized defintion rehydrated to. That way we don't...

Cache what symbols a serialized defintion rehydrated to.  That way we don't have to recompute it every time we hear about a new reference.
上级 eb3337c7
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Remote;
......@@ -19,6 +20,10 @@ private class ServerCallback
private readonly IStreamingFindReferencesProgress _progress;
private readonly CancellationToken _cancellationToken;
private readonly object _gate = new object();
private readonly Dictionary<SerializableSymbolAndProjectId, SymbolAndProjectId> _definitionMap =
new Dictionary<SerializableSymbolAndProjectId, SymbolAndProjectId>();
public ServerCallback(
Solution solution,
IStreamingFindReferencesProgress progress,
......@@ -49,14 +54,24 @@ public async Task OnDefinitionFoundAsync(SerializableSymbolAndProjectId definiti
{
var symbolAndProjectId = await definition.RehydrateAsync(
_solution, _cancellationToken).ConfigureAwait(false);
lock (_gate)
{
_definitionMap[definition] = symbolAndProjectId;
}
await _progress.OnDefinitionFoundAsync(symbolAndProjectId).ConfigureAwait(false);
}
public async Task OnReferenceFoundAsync(
SerializableSymbolAndProjectId definition, SerializableReferenceLocation reference)
{
var symbolAndProjectId = await definition.RehydrateAsync(
_solution, _cancellationToken).ConfigureAwait(false);
SymbolAndProjectId symbolAndProjectId;
lock (_gate)
{
symbolAndProjectId = _definitionMap[definition];
}
var referenceLocation = await reference.RehydrateAsync(
_solution, _cancellationToken).ConfigureAwait(false);
......
......@@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.SymbolSearch;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Remote
{
......@@ -16,11 +17,19 @@ namespace Microsoft.CodeAnalysis.Remote
/// <summary>
/// Arguments to pass from client to server when performing operations
/// </summary>
internal class SerializableProjectId
internal class SerializableProjectId : IEquatable<SerializableProjectId>
{
public Guid Id;
public string DebugName;
public override int GetHashCode()
=> Hash.Combine(Id.GetHashCode(), DebugName.GetHashCode());
public override bool Equals(object obj) => Equals(obj as SerializableProjectId);
public bool Equals(SerializableProjectId obj)
=> obj != null && Id.Equals(obj.Id) && DebugName.Equals(obj.DebugName);
public static SerializableProjectId Dehydrate(ProjectId id)
{
return new SerializableProjectId { Id = id.Id, DebugName = id.DebugName };
......@@ -80,11 +89,19 @@ public TextSpan Rehydrate()
#region FindReferences
internal class SerializableSymbolAndProjectId
internal class SerializableSymbolAndProjectId : IEquatable<SerializableSymbolAndProjectId>
{
public string SymbolKeyData;
public SerializableProjectId ProjectId;
public override int GetHashCode()
=> Hash.Combine(SymbolKeyData, ProjectId.GetHashCode());
public override bool Equals(object obj) => Equals(obj as SerializableSymbolAndProjectId);
public bool Equals(SerializableSymbolAndProjectId other)
=> other != null && SymbolKeyData.Equals(other.SymbolKeyData) && ProjectId.Equals(other.ProjectId);
public static SerializableSymbolAndProjectId Dehydrate(
IAliasSymbol alias, Document document)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册