protected override Span TrackSpan(ITextVersion targetVersion) { // Compute the new span on the requested snapshot. // // This method can be called simultaneously from multiple threads, and must be fast. // // We are relying on the atomicity of pointer copies (this.cachedSpan might change after we've // fetched it but we will always get a self-consistent VersionPosition). This ensures we // have proper behavior when called from multiple threads--multiple threads may all track and update the // cached value if called at inconvenient times, but they will return consistent results. // ForwardFidelity spans do not support tracking backward, so consistency is not guaranteed in that case. VersionSpan cached = this.cachedSpan; Span targetSpan; if (targetVersion == cached.Version) { targetSpan = cached.Span; } else if (targetVersion.VersionNumber > cached.Version.VersionNumber) { // Compute the target span by going forward from the cached version targetSpan = TrackSpanForwardInTime(cached.Span, cached.Version, targetVersion); // Update the cached value this.cachedSpan = new VersionSpan(targetVersion, targetSpan); } else { // Roll backwards from the cached version. targetSpan = TrackSpanBackwardInTime(cached.Span, cached.Version, targetVersion); } return(targetSpan); }
public ForwardFidelityTrackingSpan(ITextVersion version, Span span, SpanTrackingMode trackingMode) : base(version, span, trackingMode) { this.cachedSpan = new VersionSpan(version, span); }
public override string ToString() { VersionSpan c = this.cachedSpan; return(ToString(c.Version, c.Span, this.trackingMode)); }