提交 abd493f0 编写于 作者: C CyrusNajmabadi

Merge pull request #4401 from CyrusNajmabadi/avoidCreatingTaggers

Don't bother creating taggers when there are no diagnostics to display.
......@@ -53,6 +53,7 @@ public void Dispose()
foreach (var kvp in _idToProviderAndTagger)
{
var tagger = kvp.Value.Item2;
tagger.TagsChanged -= OnUnderlyingTaggerTagsChanged;
var disposable = tagger as IDisposable;
if (disposable != null)
......@@ -137,6 +138,15 @@ private void OnDiagnosticsUpdated(object sender, DiagnosticsUpdatedArgs e)
ValueTuple<TaggerProvider, IAccurateTagger<TTag>> providerAndTagger;
if (!_idToProviderAndTagger.TryGetValue(id, out providerAndTagger))
{
// We didn't have an existing tagger for this diagnostic id. If there are no actual
// diagnostics being reported, then don't bother actually doing anything. This saves
// us from creating a lot of objects, and subscribing to tons of events that we don't
// actually need (since we don't even have any diagnostics to show!).
if (e.Diagnostics.Length == 0)
{
return;
}
// Didn't have an existing tagger for this diagnostic id. Make a new one
// and cache it so we can use it in the future.
var taggerProvider = new TaggerProvider(_owner);
......
......@@ -339,7 +339,7 @@ private void CheckSnapshot(ITextSnapshot snapshot)
private ImmutableDictionary<ITextBuffer, TagSpanIntervalTree<TTag>> ConvertToTagTrees(
ImmutableDictionary<ITextBuffer, TagSpanIntervalTree<TTag>> oldTagTrees,
IEnumerable<ITagSpan<TTag>> newTagSpans,
ILookup<ITextBuffer, ITagSpan<TTag>> newTagsByBuffer,
IEnumerable<DocumentSnapshotSpan> spansTagged)
{
// NOTE: we assume that the following list is already realized and is _not_ lazily
......@@ -348,11 +348,10 @@ private void CheckSnapshot(ITextSnapshot snapshot)
// common case where we only tagged a single range of a document.
if (spansTagged.IsSingle())
{
return ConvertToTagTree(oldTagTrees, newTagSpans, spansTagged.Single().SnapshotSpan);
return ConvertToTagTree(oldTagTrees, newTagsByBuffer, spansTagged.Single().SnapshotSpan);
}
// heavy linq case
var newTagsByBuffer = newTagSpans.ToLookup(t => t.Span.Snapshot.TextBuffer);
var spansToInvalidateByBuffer = spansTagged.Select(ss => ss.SnapshotSpan).ToLookup(ss => ss.Snapshot.TextBuffer);
var buffers = oldTagTrees.Keys.Concat(newTagsByBuffer.Select(g => g.Key))
......@@ -432,10 +431,9 @@ private IEnumerable<ITagSpan<TTag>> GetNonIntersectingTagSpans(IEnumerable<Snaps
private ImmutableDictionary<ITextBuffer, TagSpanIntervalTree<TTag>> ConvertToTagTree(
ImmutableDictionary<ITextBuffer, TagSpanIntervalTree<TTag>> oldTagTrees,
IEnumerable<ITagSpan<TTag>> newTagSpans,
ILookup<ITextBuffer, ITagSpan<TTag>> newTagsByBuffer,
SnapshotSpan spanTagged)
{
var newTagsByBuffer = newTagSpans.ToLookup(t => t.Span.Snapshot.TextBuffer);
var allBuffers = oldTagTrees.Keys.Concat(newTagsByBuffer.Select(g => g.Key))
.Concat(spanTagged.Snapshot.TextBuffer).Distinct();
......@@ -577,7 +575,14 @@ private Task ProduceTagsAsync(TaggerContext<TTag> context)
ImmutableDictionary<ITextBuffer, TagSpanIntervalTree<TTag>> oldTagTrees,
TaggerContext<TTag> context)
{
var newTagTrees = ConvertToTagTrees(oldTagTrees, context.tagSpans, context._spansTagged);
var buffersToTag = spansToTag.Select(dss => dss.SnapshotSpan.Snapshot.TextBuffer).ToSet();
// Ignore any tag spans reported for any buffers we weren't interested in.
var newTagsByBuffer = context.tagSpans.Where(ts => buffersToTag.Contains(ts.Span.Snapshot.TextBuffer))
.ToLookup(t => t.Span.Snapshot.TextBuffer);
var newTagTrees = ConvertToTagTrees(oldTagTrees, newTagsByBuffer, context._spansTagged);
ProcessNewTagTrees(spansToTag, oldTagTrees, newTagTrees, context.State, context.CancellationToken);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册