Skip to content

Commit 87d61b7

Browse files
author
Austin Harris
committed
reduce cost of initializing 'batch' in ProcessInternal by 8% when isSignleRpc is true
1 parent c1d066c commit 87d61b7

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

Json-Rpc/JsonRpcProcessor.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Collections.Generic;
88
using System.Linq;
99
using System.Text;
10+
using Newtonsoft.Json;
1011

1112
namespace AustinHarris.JsonRpc
1213
{
@@ -60,18 +61,18 @@ private static string ProcessInternal(string sessionId, string jsonRpc, object j
6061

6162
try
6263
{
64+
Tuple<JsonRequest, JsonResponse>[] batch = null;
6365
if (isSingleRpc(jsonRpc))
6466
{
65-
var sbAddBrackets = new StringBuilder("[", jsonRpc.Length + 2);
66-
sbAddBrackets.Append(jsonRpc);
67-
sbAddBrackets.Append("]");
68-
jsonRpc = sbAddBrackets.ToString();
67+
batch = new [] { Tuple.Create(JsonConvert.DeserializeObject<JsonRequest>(jsonRpc), new JsonResponse()) };
6968
}
70-
71-
var batch =
72-
Newtonsoft.Json.JsonConvert.DeserializeObject<JsonRequest[]>(jsonRpc)
73-
.Select(request => new Tuple<JsonRequest, JsonResponse>(request, new JsonResponse())).ToArray();
74-
69+
else
70+
{
71+
batch = JsonConvert.DeserializeObject<JsonRequest[]>(jsonRpc)
72+
.Select(request => new Tuple<JsonRequest, JsonResponse>(request, new JsonResponse()))
73+
.ToArray();
74+
}
75+
7576
if (batch.Length == 0)
7677
{
7778
return Newtonsoft.Json.JsonConvert.SerializeObject(new JsonResponse

0 commit comments

Comments
 (0)