| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Collections.Generic; |
| | | 5 | | |
| | | 6 | | namespace CoreWCF |
| | | 7 | | { |
| | | 8 | | public class UriTemplateEquivalenceComparer : IEqualityComparer<UriTemplate> |
| | | 9 | | { |
| | | 10 | | private static UriTemplateEquivalenceComparer s_instance; |
| | | 11 | | |
| | | 12 | | internal static UriTemplateEquivalenceComparer Instance |
| | | 13 | | { |
| | | 14 | | get |
| | | 15 | | { |
| | 289 | 16 | | if (s_instance == null) |
| | | 17 | | { |
| | | 18 | | // lock-free, fine if we allocate more than one |
| | 3 | 19 | | s_instance = new UriTemplateEquivalenceComparer(); |
| | | 20 | | } |
| | 289 | 21 | | return s_instance; |
| | | 22 | | } |
| | | 23 | | } |
| | | 24 | | |
| | | 25 | | public bool Equals(UriTemplate x, UriTemplate y) |
| | | 26 | | { |
| | 0 | 27 | | if (x == null) |
| | | 28 | | { |
| | 0 | 29 | | return y == null; |
| | | 30 | | } |
| | | 31 | | |
| | 0 | 32 | | return x.IsEquivalentTo(y); |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | public int GetHashCode(UriTemplate obj) |
| | | 36 | | { |
| | 289 | 37 | | if (obj == null) |
| | | 38 | | { |
| | 0 | 39 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(obj)); |
| | | 40 | | } |
| | | 41 | | |
| | 674 | 42 | | for (int i = obj._segments.Count - 1; i >= 0; --i) |
| | | 43 | | { |
| | 321 | 44 | | if (obj._segments[i].Nature == UriTemplatePartType.Literal) |
| | | 45 | | { |
| | 273 | 46 | | return obj._segments[i].GetHashCode(); |
| | | 47 | | } |
| | | 48 | | } |
| | | 49 | | |
| | 16 | 50 | | return obj._segments.Count + obj._queries.Count; |
| | | 51 | | } |
| | | 52 | | } |
| | | 53 | | } |