From 36627f7da3b38dc6434c461c08e230895751fdab Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Wed, 16 Feb 2022 18:15:04 -0800 Subject: [PATCH] Normalize source files (#76) --- .../src/ComparerUtilities.cs | 282 +++++++++--------- 1 file changed, 141 insertions(+), 141 deletions(-) diff --git a/src/Microsoft.AspNetCore.Razor.Language/src/ComparerUtilities.cs b/src/Microsoft.AspNetCore.Razor.Language/src/ComparerUtilities.cs index f6e470b3c..1594cd3d4 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/src/ComparerUtilities.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/src/ComparerUtilities.cs @@ -1,141 +1,141 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Generic; -using System.Diagnostics; -using Microsoft.Extensions.Internal; - -namespace Microsoft.AspNetCore.Razor.Language; - -internal static class ComparerUtilities -{ - public static bool Equals(IReadOnlyList? first, IReadOnlyList? second, IEqualityComparer? comparer) - { - if (first == second) - { - return true; - } - - if (first is null) - { - return second is null; - } - else if (second is null) - { - return false; - } - - if (first.Count != second.Count) - { - return false; - } - - comparer ??= EqualityComparer.Default; - - for (var i = 0; i < first.Count; i++) - { - if (!comparer.Equals(first[i], second[i])) - { - return false; - } - } - - return true; - } - - public static void AddToHash(ref HashCodeCombiner hash, IReadOnlyList list, IEqualityComparer? comparer) - { - comparer ??= EqualityComparer.Default; - - for (var i = 0; i < list.Count; i++) - { - hash.Add(list[i], comparer); - } - } - - public static bool Equals(IReadOnlyDictionary? first, IReadOnlyDictionary? second, IEqualityComparer? keyComparer, IEqualityComparer? valueComparer) - where TKey : notnull - { - if (first == second) - { - return true; - } - - if (first is null) - { - return second is null; - } - else if (second is null) - { - return false; - } - - if (first.Count != second.Count) - { - return false; - } - - keyComparer ??= EqualityComparer.Default; - valueComparer ??= EqualityComparer.Default; - - // 🐇 Avoid enumerator allocations for Dictionary - if (first is Dictionary firstDictionary - && second is Dictionary secondDictionary) - { - using var firstEnumerator = firstDictionary.GetEnumerator(); - using var secondEnumerator = secondDictionary.GetEnumerator(); - while (firstEnumerator.MoveNext() && secondEnumerator.MoveNext()) - { - if (!keyComparer.Equals(firstEnumerator.Current.Key, secondEnumerator.Current.Key) - || !valueComparer.Equals(firstEnumerator.Current.Value, secondEnumerator.Current.Value)) - { - return false; - } - } - - Debug.Assert(!firstEnumerator.MoveNext() && !secondEnumerator.MoveNext(), "We already know the collections have same count."); - return true; - } - else - { - using var firstEnumerator = first.GetEnumerator(); - using var secondEnumerator = second.GetEnumerator(); - while (firstEnumerator.MoveNext() && secondEnumerator.MoveNext()) - { - if (!keyComparer.Equals(firstEnumerator.Current.Key, secondEnumerator.Current.Key) - || !valueComparer.Equals(firstEnumerator.Current.Value, secondEnumerator.Current.Value)) - { - return false; - } - } - - Debug.Assert(!firstEnumerator.MoveNext() && !secondEnumerator.MoveNext(), "We already know the collections have same count."); - return true; - } - } - - public static void AddToHash(ref HashCodeCombiner hash, IReadOnlyDictionary dictionary, IEqualityComparer? keyComparer, IEqualityComparer? valueComparer) - where TKey : notnull - { - keyComparer ??= EqualityComparer.Default; - valueComparer ??= EqualityComparer.Default; - - // 🐇 Avoid enumerator allocations for Dictionary - if (dictionary is Dictionary typedDictionary) - { - foreach (var kvp in typedDictionary) - { - hash.Add(kvp.Key, keyComparer); - hash.Add(kvp.Value, valueComparer); - } - } - else - { - foreach (var kvp in dictionary) - { - hash.Add(kvp.Key, keyComparer); - hash.Add(kvp.Value, valueComparer); - } - } - } -} +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections.Generic; +using System.Diagnostics; +using Microsoft.Extensions.Internal; + +namespace Microsoft.AspNetCore.Razor.Language; + +internal static class ComparerUtilities +{ + public static bool Equals(IReadOnlyList? first, IReadOnlyList? second, IEqualityComparer? comparer) + { + if (first == second) + { + return true; + } + + if (first is null) + { + return second is null; + } + else if (second is null) + { + return false; + } + + if (first.Count != second.Count) + { + return false; + } + + comparer ??= EqualityComparer.Default; + + for (var i = 0; i < first.Count; i++) + { + if (!comparer.Equals(first[i], second[i])) + { + return false; + } + } + + return true; + } + + public static void AddToHash(ref HashCodeCombiner hash, IReadOnlyList list, IEqualityComparer? comparer) + { + comparer ??= EqualityComparer.Default; + + for (var i = 0; i < list.Count; i++) + { + hash.Add(list[i], comparer); + } + } + + public static bool Equals(IReadOnlyDictionary? first, IReadOnlyDictionary? second, IEqualityComparer? keyComparer, IEqualityComparer? valueComparer) + where TKey : notnull + { + if (first == second) + { + return true; + } + + if (first is null) + { + return second is null; + } + else if (second is null) + { + return false; + } + + if (first.Count != second.Count) + { + return false; + } + + keyComparer ??= EqualityComparer.Default; + valueComparer ??= EqualityComparer.Default; + + // 🐇 Avoid enumerator allocations for Dictionary + if (first is Dictionary firstDictionary + && second is Dictionary secondDictionary) + { + using var firstEnumerator = firstDictionary.GetEnumerator(); + using var secondEnumerator = secondDictionary.GetEnumerator(); + while (firstEnumerator.MoveNext() && secondEnumerator.MoveNext()) + { + if (!keyComparer.Equals(firstEnumerator.Current.Key, secondEnumerator.Current.Key) + || !valueComparer.Equals(firstEnumerator.Current.Value, secondEnumerator.Current.Value)) + { + return false; + } + } + + Debug.Assert(!firstEnumerator.MoveNext() && !secondEnumerator.MoveNext(), "We already know the collections have same count."); + return true; + } + else + { + using var firstEnumerator = first.GetEnumerator(); + using var secondEnumerator = second.GetEnumerator(); + while (firstEnumerator.MoveNext() && secondEnumerator.MoveNext()) + { + if (!keyComparer.Equals(firstEnumerator.Current.Key, secondEnumerator.Current.Key) + || !valueComparer.Equals(firstEnumerator.Current.Value, secondEnumerator.Current.Value)) + { + return false; + } + } + + Debug.Assert(!firstEnumerator.MoveNext() && !secondEnumerator.MoveNext(), "We already know the collections have same count."); + return true; + } + } + + public static void AddToHash(ref HashCodeCombiner hash, IReadOnlyDictionary dictionary, IEqualityComparer? keyComparer, IEqualityComparer? valueComparer) + where TKey : notnull + { + keyComparer ??= EqualityComparer.Default; + valueComparer ??= EqualityComparer.Default; + + // 🐇 Avoid enumerator allocations for Dictionary + if (dictionary is Dictionary typedDictionary) + { + foreach (var kvp in typedDictionary) + { + hash.Add(kvp.Key, keyComparer); + hash.Add(kvp.Value, valueComparer); + } + } + else + { + foreach (var kvp in dictionary) + { + hash.Add(kvp.Key, keyComparer); + hash.Add(kvp.Value, valueComparer); + } + } + } +}