private void WriteNumberValueFormatLoop(ulong value, ref int idx)
        {
            int bytesWritten;

            // Using Utf8Formatter with default StandardFormat is roughly 30% slower (17 ns versus 12 ns)
            // See: https://github.com/dotnet/corefx/issues/25425
            // Utf8Formatter.TryFormat(value, _buffer.Slice(idx), out bytesWritten);
            while (!JsonWriterHelper.TryFormatUInt64Default(value, _buffer.Slice(idx), out bytesWritten))
            {
                AdvanceAndGrow(idx, JsonConstants.MaximumUInt64Length);
                idx = 0;
            }
            idx += bytesWritten;
        }
コード例 #2
0
        private void WriteValueFast(ulong value)
        {
            // Calculated based on the following: ',number'
            int bytesNeeded = 1 + JsonConstants.MaximumUInt64Length;

            Span <byte> byteBuffer = WriteValue(bytesNeeded, out int idx);

            bool result = JsonWriterHelper.TryFormatUInt64Default(value, byteBuffer.Slice(idx), out int bytesWritten);

            // Using Utf8Formatter with default StandardFormat is roughly 30% slower (17 ns versus 12 ns)
            // See: https://github.com/dotnet/corefx/issues/25425
            // bool result = Utf8Formatter.TryFormat(value, byteBuffer.Slice(idx), out int bytesWritten);
            Debug.Assert(result);
            idx += bytesWritten;

            Advance(idx);
        }
コード例 #3
0
        private void WriteArrayFast(ref ReadOnlySpan <byte> propertyName, ref ReadOnlySpan <ulong> values)
        {
            if (values.Length > 0 && values.Length < (int.MaxValue - 5 - propertyName.Length) / (JsonConstants.MaximumUInt64Length + 1))
            {
                // Calculated based on the following: '"propertyName":[number0,number1,...,numberN]'
                int bytesNeeded = propertyName.Length + 5 + (values.Length * (1 + JsonConstants.MaximumUInt64Length) - 1);

                if (_currentDepth >= 0)
                {
                    bytesNeeded--;
                }

                Ensure(bytesNeeded);

                WritePropertyName(ref propertyName, bytesNeeded, out int idx);

                _buffer[idx++] = JsonConstants.OpenBracket;

                bool result = JsonWriterHelper.TryFormatUInt64Default(values[0], _buffer.Slice(idx), out int bytesWritten);
                // Using Utf8Formatter with default StandardFormat is roughly 30% slower (17 ns versus 12 ns)
                // See: https://github.com/dotnet/corefx/issues/25425
                // bool result = Utf8Formatter.TryFormat(value, byteBuffer.Slice(idx), out int bytesWritten);
                Debug.Assert(result);
                idx += bytesWritten;

                for (int i = 1; i < values.Length; i++)
                {
                    _buffer[idx++] = JsonConstants.ListSeperator;

                    result = JsonWriterHelper.TryFormatUInt64Default(values[i], _buffer.Slice(idx), out bytesWritten);
                    // Using Utf8Formatter with default StandardFormat is roughly 30% slower (17 ns versus 12 ns)
                    // See: https://github.com/dotnet/corefx/issues/25425
                    // bool result = Utf8Formatter.TryFormat(value, byteBuffer.Slice(idx), out int bytesWritten);
                    Debug.Assert(result);
                    idx += bytesWritten;
                }

                _buffer[idx++] = JsonConstants.CloseBracket;

                Advance(idx);
            }
            else
            {
                WriteArrayFastIterate(ref propertyName, ref values);
            }
        }
コード例 #4
0
        private void WriteValueFormatted(ulong value)
        {
            int indent = Indentation;

            // This is guaranteed not to overflow.
            Debug.Assert(int.MaxValue - JsonConstants.MaximumUInt64Length - 1 - JsonWriterHelper.NewLineUtf8.Length - indent >= 0);

            // Calculated based on the following: ',\r\n  number'
            int bytesNeeded = 1 + JsonWriterHelper.NewLineUtf8.Length + indent + JsonConstants.MaximumUInt64Length;

            Span <byte> byteBuffer = WriteValueFormatted(bytesNeeded, indent, out int idx);

            bool result = JsonWriterHelper.TryFormatUInt64Default(value, byteBuffer.Slice(idx), out int bytesWritten);

            // Using Utf8Formatter with default StandardFormat is roughly 30% slower (17 ns versus 12 ns)
            // See: https://github.com/dotnet/corefx/issues/25425
            // bool result = Utf8Formatter.TryFormat(value, byteBuffer.Slice(idx), out int bytesWritten);
            Debug.Assert(result);
            idx += bytesWritten;

            Advance(idx);
        }