unsafe public bool Equals2(int offset1, int length1, string s2)
{
int byteLength = length1;
int charLength = s2.Length;
// N Unicode chars will be represented in at least N bytes, but
// no more than N * 3 bytes. If the byte count falls outside of this
// range, then the strings cannot be equal.
if (byteLength < charLength || byteLength > charLength * maxBytesPerChar)
return false;
byte[] buffer = _buffer;
if (length1 < 8)
{
int length = Math.Min(byteLength, charLength);
int offset = offset1;
for (int i = 0; i < length; i++)
{
byte b = buffer[offset + i];
if (b >= 0x80)
return XmlConverter.ToString(buffer, offset1, length1) == s2;
if (s2[i] != (char)b)
return false;
}
return byteLength == charLength;
}
else
{
int length = Math.Min(byteLength, charLength);
fixed (byte* _pb = &buffer[offset1])
{
byte* pb = _pb;
byte* pbMax = pb + length;
fixed (char* _pch = s2)
{
char* pch = _pch;
// Try to do the fast comparison in ASCII space
int t = 0;
while (pb < pbMax && *pb < 0x80)
{
t = *pb - (byte)*pch;
// The code generated is better if we break out then return
if (t != 0)
break;
pb++;
pch++;
}
if (t != 0)
return false;
if (pb == pbMax)
return (byteLength == charLength);
}
}
return XmlConverter.ToString(buffer, offset1, length1) == s2;
}
}