Repository: dotnet/roslyn
File: src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/EmbeddedLanguages/VirtualChars/VirtualCharSequence.cs (C#)

Code before:
    private readonly VirtualCharGreenSequence _sequence;

    public static readonly VirtualCharSequence Empty = new(0, VirtualCharGreenSequence.Empty);

    public static VirtualCharSequence Create(int tokenStart, string text)
        => new(tokenStart, VirtualCharGreenSequence.Create(text));

    public static VirtualCharSequence Create(ImmutableSegmentedList<VirtualChar> virtualChars)
    {
        if (virtualChars.IsEmpty)
            return Empty;

        // Determine the earliest token start of all of the virtual chars.  This will be where this entire sequence
        // starts.  Any virtual chars with the same token start will keep their same offset.  Any virtual chars with a
        // later token start will have their offset adjusted to be relative to this new start.
        var minimumTokenStart = virtualChars.Min(static c => c.TokenStart);

        using var pooledObject = s_builderPool.GetPooledObject();
        var builder = pooledObject.Object;

        foreach (var ch in virtualChars)
        {
            Debug.Assert(ch.TokenStart >= minimumTokenStart);
            var offsetDifference = ch.TokenStart - minimumTokenStart;
            var newGreen = ch.Green.WithOffset(ch.Green.Offset + offsetDifference);
            builder.Add(newGreen);
        }

        var result = new VirtualCharSequence(minimumTokenStart, VirtualCharGreenSequence.Create(builder.ToImmutable()));
        builder.Clear();

        return result;
    }

    public VirtualCharSequence(int tokenStart, VirtualCharGreenSequence sequence)
    {
        if (tokenStart < 0)
            throw new ArgumentException("tokenStart cannot be negative", nameof(tokenStart));

        _tokenStart = tokenStart;
        _sequence = sequence;
    }

    /// <inheritdoc cref="VirtualCharGreenSequence.Length"/>
    public int Length => _sequence.Length;

    public VirtualChar this[int index]
        => new(_sequence[index], _tokenStart);

    /// <inheritdoc cref="VirtualCharGreenSequence.Find"/>
    public VirtualChar? Find(int position)

Review comment (suggestion):
note: we'll still need this (sicne it is effectively the null-check on a struct).  But i will likely be removing isEmpty and IsDefaultOrEmpty as string itself doesn't have those.  

Code after:
        if (tokenStart < 0)
            throw new ArgumentException("tokenStart cannot be negative", nameof(tokenStart));

        _tokenStart = tokenStart;
        _sequence = sequence;
    }

    /// <inheritdoc cref="VirtualCharGreenSequence.Length"/>
    public int Length => _sequence.Length;

    public VirtualChar this[int index]
        => new(_sequence[index], _tokenStart);

    /// <inheritdoc cref="VirtualCharGreenSequence.Find"/>
    public VirtualChar? Find(int position)
        => _sequence.Find(_tokenStart, position)?.virtualChar;

    /// <summary>
    /// Returns the index of the <see cref="VirtualChar"/> in this <see cref="VirtualCharSequence"/> that contains the
    /// given position. Will return null if this position is not in the span of this sequence.
    /// </summary>
    public int? FindIndex(int position)
        => _sequence.Find(_tokenStart, position)?.index;

    /// <inheritdoc cref="VirtualCharGreenSequence.IsDefault"/>
    public bool IsDefault => _sequence.IsDefault;

    /// <inheritdoc cref="VirtualCharGreenSequence.Slice"/>
    public VirtualCharSequence Slice(int start, int length)
       => new(_tokenStart, _sequence.Slice(start, length));

    public Enumerator GetEnumerator()
        => new(this);

    [Conditional("DEBUG")]
    public void AssertAdjacentTo(VirtualCharSequence virtualChars)
    {
        _sequence.AssertAdjacentTo(virtualChars._sequence);
    }

    /// <summary>
    /// Combines two <see cref="VirtualCharSequence"/>s, producing a final sequence that points at the same underlying
    /// data, but spans from the start of <paramref name="chars1"/> to the end of <paramref name="chars2"/>.
    /// </summary>  
    [Obsolete("Only around for ASP.NET compatibility. Do not use anymore.", error: false)]
    public static VirtualCharSequence FromBounds(
        VirtualCharSequence chars1, VirtualCharSequence chars2)
    {
        Debug.Assert(chars1._tokenStart == chars2._tokenStart);
        return new VirtualCharSequence(
            chars1._tokenStart,