[Fixes #4092] Using System.Buffers in JsonResultExecutor
This commit is contained in:
parent
b39f4dfe29
commit
df5eb0a15c
|
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Buffers;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
|
|
@ -22,6 +23,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal
|
||||||
Encoding = Encoding.UTF8
|
Encoding = Encoding.UTF8
|
||||||
}.ToString();
|
}.ToString();
|
||||||
|
|
||||||
|
private readonly IArrayPool<char> _charPool;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="JsonResultExecutor"/>.
|
/// Creates a new <see cref="JsonResultExecutor"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -31,7 +34,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal
|
||||||
public JsonResultExecutor(
|
public JsonResultExecutor(
|
||||||
IHttpResponseStreamWriterFactory writerFactory,
|
IHttpResponseStreamWriterFactory writerFactory,
|
||||||
ILogger<JsonResultExecutor> logger,
|
ILogger<JsonResultExecutor> logger,
|
||||||
IOptions<MvcJsonOptions> options)
|
IOptions<MvcJsonOptions> options,
|
||||||
|
ArrayPool<char> charPool)
|
||||||
{
|
{
|
||||||
if (writerFactory == null)
|
if (writerFactory == null)
|
||||||
{
|
{
|
||||||
|
|
@ -48,9 +52,15 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal
|
||||||
throw new ArgumentNullException(nameof(options));
|
throw new ArgumentNullException(nameof(options));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (charPool == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(charPool));
|
||||||
|
}
|
||||||
|
|
||||||
WriterFactory = writerFactory;
|
WriterFactory = writerFactory;
|
||||||
Logger = logger;
|
Logger = logger;
|
||||||
Options = options.Value;
|
Options = options.Value;
|
||||||
|
_charPool = new JsonArrayPool<char>(charPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -111,6 +121,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal
|
||||||
{
|
{
|
||||||
using (var jsonWriter = new JsonTextWriter(writer))
|
using (var jsonWriter = new JsonTextWriter(writer))
|
||||||
{
|
{
|
||||||
|
jsonWriter.ArrayPool = _charPool;
|
||||||
jsonWriter.CloseOutput = false;
|
jsonWriter.CloseOutput = false;
|
||||||
|
|
||||||
var jsonSerializer = JsonSerializer.Create(serializerSettings);
|
var jsonSerializer = JsonSerializer.Create(serializerSettings);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System.Buffers;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
@ -161,7 +162,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal
|
||||||
return new JsonResultExecutor(
|
return new JsonResultExecutor(
|
||||||
new TestHttpResponseStreamWriterFactory(),
|
new TestHttpResponseStreamWriterFactory(),
|
||||||
NullLogger<JsonResultExecutor>.Instance,
|
NullLogger<JsonResultExecutor>.Instance,
|
||||||
new TestOptionsManager<MvcJsonOptions>());
|
new TestOptionsManager<MvcJsonOptions>(),
|
||||||
|
ArrayPool<char>.Shared);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HttpContext GetHttpContext()
|
private static HttpContext GetHttpContext()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System.Buffers;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
@ -46,7 +47,8 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
var executor = new JsonResultExecutor(
|
var executor = new JsonResultExecutor(
|
||||||
new TestHttpResponseStreamWriterFactory(),
|
new TestHttpResponseStreamWriterFactory(),
|
||||||
NullLogger<JsonResultExecutor>.Instance,
|
NullLogger<JsonResultExecutor>.Instance,
|
||||||
new TestOptionsManager<MvcJsonOptions>());
|
new TestOptionsManager<MvcJsonOptions>(),
|
||||||
|
ArrayPool<char>.Shared);
|
||||||
|
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton(executor);
|
services.AddSingleton(executor);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue