Beispiel #1
0
 private void WriteControl(byte value)
 {
     if (UseFastUtf8)
     {
         EnsureBuffer(1).DangerousGetPinnableReference() = value;
         _output.Advance(1);
     }
     else if (UseFastUtf16)
     {
         var buffer = EnsureBuffer(2);
         Unsafe.As <byte, char>(ref buffer.DangerousGetPinnableReference()) = (char)value;
         _output.Advance(2);
     }
     else
     {
         unsafe
         {
             // Slow path, if we are dealing with non-invariant.
             char ch = (char)value;
             ReadOnlySpan <char> chSpan = new ReadOnlySpan <char>(&ch, 1);
             Write(chSpan);
         }
     }
 }
Beispiel #2
0
        private void WriteControl(byte value)
        {
            if (UseFastUtf8)
            {
                EnsureBuffer(1).DangerousGetPinnableReference() = value;
                _output.Advance(1);
            }
            else if (UseFastUtf16)
            {
                var buffer = EnsureBuffer(2);
                Unsafe.As <byte, char>(ref buffer.DangerousGetPinnableReference()) = (char)value;
                _output.Advance(2);
            }
            else
            {
                var buffer = _output.GetSpan();
                int written;
                while (!_output.SymbolTable.TryEncode(value, buffer, out written))
                {
                    buffer = EnsureBuffer();
                }

                _output.Advance(written);
            }
        }
Beispiel #3
0
        private void WriteControl(byte value)
        {
            if (UseFastUtf8)
            {
                MemoryMarshal.GetReference(EnsureBuffer(1)) = value;
                _output.Advance(1);
            }
            else if (UseFastUtf16)
            {
                var buffer = EnsureBuffer(2);
                Unsafe.As <byte, char>(ref MemoryMarshal.GetReference(buffer)) = (char)value;
                _output.Advance(2);
            }
            else
            {
                var buffer = _output.GetSpan();
                int written;
                while (!_output.SymbolTable.TryEncode(value, buffer, out written))
                {
                    buffer = EnsureBuffer();
                }

                _output.Advance(written);
            }
        }