public static unsafe LazyUTF8String FromByteArray(byte *bufferPtr, int length) { bytePool.MakeFreeSpace(length); LazyUTF8String lazyString = stringPool.GetNew(); byte *poolPtrForLoop = bytePool.RawPointer + bytePool.FreeIndex; byte *bufferPtrForLoop = bufferPtr; int index = 0; while (index < length) { if (*bufferPtrForLoop <= 127) { *poolPtrForLoop = *bufferPtrForLoop; } else { // The string has non-ASCII characters in it, fall back to full parsing lazyString.SetToString(Encoding.UTF8.GetString(bufferPtr, length)); return(lazyString); } ++poolPtrForLoop; ++bufferPtrForLoop; ++index; } lazyString.ResetState(bytePool.FreeIndex, length); bytePool.AdvanceFreeIndex(length); return(lazyString); }