System.Text.Latin1Encoding.GetChars C# (CSharp) Method

GetChars() private method

private GetChars ( byte bytes, int byteCount, char chars, int charCount, DecoderNLS decoder ) : int
bytes byte
byteCount int
chars char
charCount int
decoder DecoderNLS
return int
        internal override unsafe int GetChars(byte* bytes, int byteCount,
                                                char* chars, int charCount, DecoderNLS decoder)
        {
            // Just need to ASSERT, this is called by something else internal that checked parameters already
            BCLDebug.Assert(bytes != null, "[Latin1Encoding.GetChars]bytes is null");
            BCLDebug.Assert(byteCount >= 0, "[Latin1Encoding.GetChars]byteCount is negative");
            BCLDebug.Assert(chars != null, "[Latin1Encoding.GetChars]chars is null");
            BCLDebug.Assert(charCount >= 0, "[Latin1Encoding.GetChars]charCount is negative");

            // Need byteCount chars, otherwise too small buffer
            if (charCount < byteCount)
            {
                // Buffer too small.  Do we throw?
                ThrowCharsOverflow(decoder, charCount < 1);

                // Don't throw, correct buffer size
                byteCount = charCount;
            }

            // Do it our fast way
            byte* byteEnd = bytes + byteCount;

            // Quick loop, all bytes are the same as chars, so no fallbacks for latin1
            while (bytes < byteEnd)
            {
                *(chars) = unchecked((char)*(bytes));
                chars++;
                bytes++;
            }

            // Might need to know input bytes used
            if (decoder != null)
                decoder.m_bytesUsed = byteCount;

            // Converted sequence is same length as input, so output charsUsed is same as byteCount;
            return byteCount;
        }