public override int GetChars( byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex ) {
int charCount = GetCharCount( bytes, byteIndex, byteCount );
if ( lastByte >= 0 ) {
if ( byteCount == 0 ) {
return charCount;
}
int nextByte = bytes[byteIndex++];
byteCount--;
chars[charIndex++] = bigEndian
? (char)( lastByte << 8 | nextByte )
: (char)( nextByte << 8 | lastByte );
lastByte = -1;
}
if ( ( byteCount & 1 ) != 0 ) {
lastByte = bytes[byteIndex + --byteCount];
}
// use the fast BlockCopy if possible
if ( bigEndian == BitConverter.IsLittleEndian ) {
int byteEnd = byteIndex + byteCount;
if ( bigEndian ) {
while ( byteIndex < byteEnd ) {
int hi = bytes[byteIndex++];
int lo = bytes[byteIndex++];
chars[charIndex++] = (char)( hi << 8 | lo );
}
}
else {
while ( byteIndex < byteEnd ) {
int lo = bytes[byteIndex++];
int hi = bytes[byteIndex++];
chars[charIndex++] = (char)( hi << 8 | lo );
}
}
}
else {
Buffer.BlockCopy( bytes, byteIndex, chars, charIndex * CharSize, byteCount );
}
return charCount;
}