Skip to content

Commit ca3700e

Browse files
Reduce memory allocations when creating a record object (#767)
1 parent 2ce243d commit ca3700e

File tree

2 files changed

+7
-30
lines changed

2 files changed

+7
-30
lines changed

Neo4j.Driver/Neo4j.Driver/Internal/Helpers/Throw.cs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,12 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
using System;
17-
1816
namespace Neo4j.Driver.Internal.Helpers;
1917

2018
internal static class Throw
2119
{
2220
public static class ProtocolException
2321
{
24-
public static void IfNotEqual(int first, int second, string firstParam, string secondParam)
25-
{
26-
If(() => first != second, first, second, firstParam, secondParam);
27-
}
28-
29-
internal static void IfNotEqual(object first, object second, string firstParam, string secondParam)
30-
{
31-
if (first == null && second == null)
32-
{
33-
return;
34-
}
35-
36-
If(() => first == null || second == null || !first.Equals(second), first, second, firstParam, secondParam);
37-
}
38-
39-
public static void If(Func<bool> func, object first, object second, string firstParam, string secondParam)
40-
{
41-
if (func())
42-
{
43-
throw new Neo4j.Driver.ProtocolException(
44-
$"{firstParam} ({first}) does not equal to {secondParam} ({second})");
45-
}
46-
}
47-
4822
public static void IfFalse(bool value, string nameofValue)
4923
{
5024
if (!value)

Neo4j.Driver/Neo4j.Driver/Internal/Result/Record.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@
1414
// limitations under the License.
1515

1616
using System.Collections.Generic;
17-
using Neo4j.Driver.Internal.Helpers;
1817

1918
namespace Neo4j.Driver.Internal.Result;
2019

2120
internal class Record : IRecord
2221
{
2322
public Record(string[] keys, object[] values)
2423
{
25-
Throw.ProtocolException.IfNotEqual(keys.Length, values.Length, nameof(keys), nameof(values));
26-
27-
var valueKeys = new Dictionary<string, object>();
24+
if (keys.Length != values.Length)
25+
{
26+
throw new ProtocolException(
27+
$"{nameof(keys)} length ({keys.Length}) does not equal to {nameof(values)} length ({values.Length})");
28+
}
29+
30+
var valueKeys = new Dictionary<string, object>(keys.Length);
2831

2932
for (var i = 0; i < keys.Length; i++)
3033
{

0 commit comments

Comments
 (0)