forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathByteArrayKeyComparer.cs
More file actions
29 lines (25 loc) · 1 KB
/
ByteArrayKeyComparer.cs
File metadata and controls
29 lines (25 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// -----------------------------------------------------------------------
// <copyright file="ByteArrayKeyComparer.cs" company="Asynkron HB">
// Copyright (C) 2015-2017 Asynkron HB All rights reserved
// </copyright>
// -----------------------------------------------------------------------
using System.Collections.Generic;
namespace Wire.Internal
{
/// <summary>
/// By default ByteArrayKey overrides "public bool Equals(object obj)" to do comparisons.
/// But this causes boxing/allocations, so by having a custom comparer we can prevent that.
/// </summary>
internal class ByteArrayKeyComparer : IEqualityComparer<ByteArrayKey>
{
public static readonly ByteArrayKeyComparer Instance = new ByteArrayKeyComparer();
public bool Equals(ByteArrayKey x, ByteArrayKey y)
{
return ByteArrayKey.Compare(x.Bytes, y.Bytes);
}
public int GetHashCode(ByteArrayKey obj)
{
return obj.GetHashCode();
}
}
}