Source/NFX/IOMiscUtils.cs
/// <summary>
/// Returns true if both buffers contain the same number of the same bytes.
/// The implementation uses quad-word comparison as much as possible for speed.
/// Requires UNSAFE switch
/// </summary>
Returns true if both buffers contain the same number of the same bytes.
The implementation uses quad-word comparison as much as possible for speed.
Requires UNSAFE switch
Returns true if both buffers contain the same number of the same bytes . The implementation uses quad - word comparison as much as possible for speed . Requires UNSAFE switch
public static unsafe bool MemBufferEquals(this byte[] buf1, byte[] buf2)
        {
           if (buf1==null || buf2==null) return false;
           var len = buf1.Length;
           if (len != buf2.Length) return false;
           var len8 = len >> 3;
           fixed (byte* pb1=buf1, pb2=buf2)
           {
              byte* p1=pb1, p2=pb2;
              for (int i=0; i < len8; i++, p1+=8, p2+=8)
                if (*((long*)p1) != *((long*)p2)) return false;
              if ((len & 4)!=0)
              {
                 if (*((int*)p1)!=*((int*)p2)) return false;
                 p1+=4; p2+=4;
              }
              if ((len & 2)!=0)
              {
                 if (*((short*)p1)!=*((short*)p2)) return false;
                 p1+=2; p2+=2;
              }
              if ((len & 1)!=0)
                if (*((byte*)p1) != *((byte*)p2)) return false;
              return true;
           }
        }
public static unsafe bool MemBufferEquals ( this byte [ ] buf1 , byte [ ] buf2 ) { if ( buf1 == null || buf2 == null ) return false ; var len = buf1 . Length ; if ( len != buf2 . Length ) return false ; var len8 = len >> 3 ; fixed ( byte * pb1 = buf1 , pb2 = buf2 ) { byte * p1 = pb1 , p2 = pb2 ; for ( int i = 0 ; i < len8 ; i ++ , p1 += 8 , p2 += 8 ) if ( * ( ( long * ) p1 ) != * ( ( long * ) p2 ) ) return false ; if ( ( len & 4 ) != 0 ) { if ( * ( ( int * ) p1 ) != * ( ( int * ) p2 ) ) return false ; p1 += 4 ; p2 += 4 ; } if ( ( len & 2 ) != 0 ) { if ( * ( ( short * ) p1 ) != * ( ( short * ) p2 ) ) return false ; p1 += 2 ; p2 += 2 ; } if ( ( len & 1 ) != 0 ) if ( * ( ( byte * ) p1 ) != * ( ( byte * ) p2 ) ) return false ; return true ; } }
Returns true if both buffers contain the same number of the same bytes.
Returns true if both buffers contain the same number of the same bytes .
//remainders after loop //fixed
byte[]
this
buf2
byte[]