private unsafe bool CompareStringEqualsName(String name)
{
BCLDebug.Assert(_store != null, "ResourceReader is closed!");
//int byteLen = Read7BitEncodedInt(_store);
int byteLen = _store.Read7BitEncodedInt();
if (_ums != null) {
//BCLDebug.Log("RESMGRFILEFORMAT", "CompareStringEqualsName using UnmanagedMemoryStream code path");
byte* bytes = _ums.PositionPointer;
// Skip over the data in the Stream, positioning ourselves right after it.
_ums.Seek(byteLen, SeekOrigin.Current);
if (_ums.Position > _ums.Length)
throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ResourcesNameTooLong"));
// On 64-bit machines, these char*'s may be misaligned. Use a
// byte-by-byte comparison instead.
//return FastResourceComparer.CompareOrdinal((char*)bytes, byteLen/2, name) == 0;
return FastResourceComparer.CompareOrdinal(bytes, byteLen, name) == 0;
}
else {
// This code needs to be fast
byte[] bytes = new byte[byteLen];
int numBytesToRead = byteLen;
while(numBytesToRead > 0) {
int n = _store.Read(bytes, byteLen - numBytesToRead, numBytesToRead);
if (n == 0)
throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ResourceNameCorrupted"));
numBytesToRead -= n;
}
return FastResourceComparer.CompareOrdinal(bytes, byteLen/2, name) == 0;
}
}