public ChangeInfo(ImmutableArray <TextChangeRange> changeRanges, WeakReference <SourceText> weakOldText, ChangeInfo?previous) { this.ChangeRanges = changeRanges; this.WeakOldText = weakOldText; this.Previous = previous; Clean(); }
private static IReadOnlyList <ImmutableArray <TextChangeRange> > GetChangesBetween(SourceText oldText, ChangedText newText) { var list = new List <ImmutableArray <TextChangeRange> >(); ChangeInfo?change = newText._info; list.Add(change.ChangeRanges); while (change != null) { SourceText?actualOldText; change.WeakOldText.TryGetTarget(out actualOldText); if (actualOldText == oldText) { return(list); } change = change.Previous; if (change != null) { list.Insert(0, change.ChangeRanges); } } // did not find old text, so not connected? list.Clear(); return(list); }
private bool IsChangedFrom(SourceText oldText) { for (ChangeInfo?info = _info; info != null; info = info.Previous) { SourceText?text; if (info.WeakOldText.TryGetTarget(out text) && text == oldText) { return(true); } } return(false); }
private void Clean() { // look for last info in the chain that still has reference to old text ChangeInfo? lastInfo = this; for (ChangeInfo? info = this; info != null; info = info.Previous) { SourceText tmp; if (info.WeakOldText.TryGetTarget(out tmp)) { lastInfo = info; } } // break chain for any info's beyond that so they get GC'd ChangeInfo? prev; while (lastInfo != null) { prev = lastInfo.Previous; lastInfo.Previous = null; lastInfo = prev; } }