From 7b39058d404fac47089d088fecc66e8061f05ff1 Mon Sep 17 00:00:00 2001
From: Pranav K <prkrishn@hotmail.com>
Date: Thu, 12 Aug 2021 16:05:02 -0700
Subject: [PATCH] Avoids boxing in HashCodeCombiner (#35208)

* Avoids boxing in HashCodeCombiner

Based on https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1366879?src=WorkItemMention&src-action=artifact_link
---
 .../src/DefaultBoundAttributeDescriptor.cs    |  4 +--
 .../HashCodeCombiner/HashCodeCombiner.cs      | 31 ++-----------------
 2 files changed, 4 insertions(+), 31 deletions(-)

diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultBoundAttributeDescriptor.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultBoundAttributeDescriptor.cs
index 23f5c49342f..dcb89740be0 100644
--- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultBoundAttributeDescriptor.cs
+++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultBoundAttributeDescriptor.cs
@@ -5,7 +5,7 @@ using System.Collections.Generic;
 
 namespace Microsoft.AspNetCore.Razor.Language
 {
-    internal class DefaultBoundAttributeDescriptor : BoundAttributeDescriptor
+    internal sealed class DefaultBoundAttributeDescriptor : BoundAttributeDescriptor
     {
         public DefaultBoundAttributeDescriptor(
             string kind,
@@ -44,4 +44,4 @@ namespace Microsoft.AspNetCore.Razor.Language
             IsBooleanProperty = typeName == typeof(bool).FullName || typeName == "bool";
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/Shared/HashCodeCombiner/HashCodeCombiner.cs b/src/Shared/HashCodeCombiner/HashCodeCombiner.cs
index aa12cd51ea7..40bd228b4a1 100644
--- a/src/Shared/HashCodeCombiner/HashCodeCombiner.cs
+++ b/src/Shared/HashCodeCombiner/HashCodeCombiner.cs
@@ -25,25 +25,6 @@ namespace Microsoft.Extensions.Internal
             _combinedHash64 = seed;
         }
 
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public void Add(IEnumerable e)
-        {
-            if (e == null)
-            {
-                Add(0);
-            }
-            else
-            {
-                var count = 0;
-                foreach (object? o in e)
-                {
-                    Add(o);
-                    count++;
-                }
-                Add(count);
-            }
-        }
-
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
         public static implicit operator int(HashCodeCombiner self)
         {
@@ -57,17 +38,9 @@ namespace Microsoft.Extensions.Internal
         }
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public void Add(string? s)
-        {
-            var hashCode = (s != null) ? s.GetHashCode() : 0;
-            Add(hashCode);
-        }
-
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public void Add(object? o)
+        public void Add<T>(T? o)
         {
-            var hashCode = (o != null) ? o.GetHashCode() : 0;
-            Add(hashCode);
+            Add(o?.GetHashCode() ?? 0);
         }
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-- 
GitLab