Esempio n. 1
0
 public ChangeInfo(ImmutableArray <TextChangeRange> changeRanges, WeakReference <SourceText> weakOldText, ChangeInfo?previous)
 {
     this.ChangeRanges = changeRanges;
     this.WeakOldText  = weakOldText;
     this.Previous     = previous;
     Clean();
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
            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;
                }
            }