/// <summary> /// Returns <c>true</c> if and only if the two specified buffers are /// identical to each other for {@code length} bytes starting at {@code aStartIndex} /// index for the {@code a} buffer and {@code bStartIndex} index for the {@code b} buffer. /// A more compact way to express this is: /// <p /> /// {@code a[aStartIndex : aStartIndex + length] == b[bStartIndex : bStartIndex + length]} /// </summary> public static bool Equals(IByteBuffer a, int aStartIndex, IByteBuffer b, int bStartIndex, int length) { if (aStartIndex < 0 || bStartIndex < 0 || length < 0) { ThrowHelper.ThrowArgumentException_NonNegative(); } if (a.WriterIndex - length < aStartIndex || b.WriterIndex - length < bStartIndex) { return(false); } if (a.IsSingleIoBuffer && b.IsSingleIoBuffer) { var spanA = a.GetReadableSpan(aStartIndex, length); var spanB = b.GetReadableSpan(bStartIndex, length); return(SpanHelpers.SequenceEqual(ref MemoryMarshal.GetReference(spanA), ref MemoryMarshal.GetReference(spanB), length)); } return(EqualsSlow(a, aStartIndex, b, bStartIndex, length)); }