/// <summary> /// Determines whether two spans are equal (byte-wise) by comparing the elements by using memcmp /// </summary> /// <param name="first">A span of shorts to compare to second.</param> /// <param name="second">A span of shorts T to compare to first.</param> public static bool SequenceEqual(this Span <short> first, Span <short> second) { if (first.Length != second.Length) { return(false); } // pinvoke calls are expensive (mostly due to memory pinning) so we call memcmp only for big slices if (first.Length >= 512) { return(MemoryUtils.MemCmp(first, second)); } // for small slices we just use simple loop for (int i = 0; i < first.Length; i++) { if (first.GetItemWithoutBoundariesCheck(i) != second.GetItemWithoutBoundariesCheck(i)) { return(false); } } return(true); }
/// <summary> /// Determines whether two read-only spans are equal (byte-wise) by comparing the elements by using memcmp /// </summary> /// <param name="first">A span of integers to compare to second.</param> /// <param name="second">A span of integers T to compare to first.</param> public static bool SequenceEqual(this ReadOnlySpan <int> first, ReadOnlySpan <int> second) { return(first.Length >= 256 ? MemoryUtils.MemCmp(first, second) : SequenceEqual <int>(first, second)); }
/// <summary> /// Determines whether two spans are equal (byte-wise) by comparing the elements by using memcmp /// </summary> /// <param name="first">A span of shorts to compare to second.</param> /// <param name="second">A span of shorts T to compare to first.</param> public static bool SequenceEqual(this Span <short> first, Span <short> second) { return(first.Length >= 512 ? MemoryUtils.MemCmp(first, second) : SequenceEqual <short>(first, second)); }
/// <summary> /// Determines whether two read-only spans are equal (byte-wise) by comparing the elements by using memcmp /// </summary> /// <param name="first">A span of characters to compare to second.</param> /// <param name="second">A span of characters T to compare to first.</param> public static bool SequenceEqual(this ReadOnlySpan <char> first, ReadOnlySpan <char> second) { return(first.Length >= 512 ? MemoryUtils.MemCmp(first, second) : SequenceEqual <char>(first, second)); }
/// <summary> /// Determines whether two read-only spans are equal (byte-wise) by comparing the elements by using memcmp /// </summary> /// <param name="first">A span of bytes to compare to second.</param> /// <param name="second">A span of bytes T to compare to first.</param> public static bool SequenceEqual(this ReadOnlySpan <byte> first, ReadOnlySpan <byte> second) { return(first.Length >= 320 ? MemoryUtils.MemCmp(first, second) : SequenceEqual <byte>(first, second)); }
/// <summary> /// Determines whether two spans are equal (byte-wise) by comparing the elements by using memcmp /// </summary> /// <param name="first">A span of long integers to compare to second.</param> /// <param name="second">A span of long integers T to compare to first.</param> public static bool SequenceEqual(this Span <long> first, Span <long> second) { return(first.Length >= 256 ? MemoryUtils.MemCmp(first, second) : SequenceEqual <long>(first, second)); }