Skip to content

Commit 4b08ea9

Browse files
author
Austin Harris
committed
Improve perf of ProcessInternal by ~ 4%
1 parent 87d61b7 commit 4b08ea9

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

Json-Rpc/JsonRpcProcessor.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,14 @@ private static string ProcessInternal(string sessionId, string jsonRpc, object j
114114
}
115115
}
116116

117-
var responses = batch.Select(tuple => tuple.Item2)
118-
.Where(resp => resp.Id != null || resp.Error != null)
119-
.Select(Newtonsoft.Json.JsonConvert.SerializeObject).ToArray();
117+
var responses = new string[batch.Count(x=>x.Item2.Id!=null || x.Item2.Error != null)];
118+
var idx = 0;
119+
foreach (var resp in batch.Where(x => x.Item2.Id != null || x.Item2.Error != null))
120+
{
121+
responses[idx++] = JsonConvert.SerializeObject(resp.Item2);
122+
}
120123

121-
return responses.Count() > 1 ? string.Format("[{0}]", string.Join(",", responses)) : responses.First();
124+
return responses.Length == 1 ? responses[0] : string.Format("[{0}]", string.Join(",", responses));
122125
}
123126
catch (Exception ex)
124127
{

0 commit comments

Comments
 (0)