コード例 #1
0
        //
        // utf8.Length does *not* include NUL terminator.
        //
        public static unsafe bool Equals(this StringHandle handle, ReadOnlySpan <byte> utf8, MetadataReader reader)
        {
            //TODO: Perf - GetBlobReader() scans the string handle for a NUL terminator to compute the length making it an O(N)
            // operation. It might be worth memoizing the pointer/length combo per TypeDefToken and ExportedTypeToken. But even better
            // would be to get UTF8 Equals overloads added to MetadataStringComparer.
            BlobReader          br     = handle.GetBlobReader(reader);
            ReadOnlySpan <byte> actual = new ReadOnlySpan <byte>(br.CurrentPointer, br.Length);

            return(utf8.SequenceEqual(actual));
        }