Example #1
0
        public static void ZeroLengthSequenceCompareTo_Char()
        {
            var a = new char[3];

            var first  = new Span <char>(a, 1, 0);
            var second = new ReadOnlySpan <char>(a, 2, 0);
            int result = SpanHelpers.SequenceCompareTo(ref MemoryMarshal.GetReference(first), first.Length, ref MemoryMarshal.GetReference(second), second.Length);

            Assert.Equal(0, result);
        }
 public static int Compare(IByteBuffer bufferA, IByteBuffer bufferB)
 {
     if (bufferA.IsSingleIoBuffer && bufferB.IsSingleIoBuffer)
     {
         var spanA = bufferA.GetReadableSpan();
         var spanB = bufferB.GetReadableSpan();
         return(SpanHelpers.SequenceCompareTo(ref MemoryMarshal.GetReference(spanA), spanA.Length, ref MemoryMarshal.GetReference(spanB), spanB.Length));
     }
     return(CompareSlow(bufferA, bufferB));
 }
Example #3
0
        //
        // Compares the specified string to this string using the ASCII values of the characters. Returns 0 if the strings
        // contain the same characters in the same order. Returns a negative integer if the first non-equal character in
        // this string has an ASCII value which is less than the ASCII value of the character at the same position in the
        // specified string, or if this string is a prefix of the specified string. Returns a positive integer if the first
        // non-equal character in this string has a ASCII value which is greater than the ASCII value of the character at
        // the same position in the specified string, or if the specified string is a prefix of this string.
        //
        public int CompareTo(AsciiString other)
        {
            if (ReferenceEquals(this, other))
            {
                return(0);
            }

            return(SpanHelpers.SequenceCompareTo(
                       ref MemoryMarshal.GetReference(this.AsciiSpan), this.length,
                       ref MemoryMarshal.GetReference(other.AsciiSpan), other.Count));
        }