private unsafe void UnsafeWriteName(char* chars, int charCount)
{
if (charCount < 128 / maxBytesPerChar)
{
// Optimize if we know we can fit the converted string in the buffer
// so we don't have to make a pass to count the bytes
// 1 byte for the length
int offset;
byte[] buffer = GetBuffer(1 + charCount * maxBytesPerChar, out offset);
int length = UnsafeGetUTF8Chars(chars, charCount, buffer, offset + 1);
DiagnosticUtility.DebugAssert(length < 128, "");
buffer[offset] = (byte)length;
Advance(1 + length);
}
else
{
int byteCount = UnsafeGetUTF8Length(chars, charCount);
WriteMultiByteInt32(byteCount);
UnsafeWriteUTF8Chars(chars, charCount);
}
}