]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
feat: make ReagentId hash by value (#39494)
authorPerry Fraser <perryprog@users.noreply.github.com>
Mon, 11 Aug 2025 22:44:10 +0000 (18:44 -0400)
committerGitHub <noreply@github.com>
Mon, 11 Aug 2025 22:44:10 +0000 (15:44 -0700)
Content.Shared/Chemistry/Reagent/ReagentId.cs

index 798dd28db490aeab83ad55dc8308f04804795b35..88c0abff2a5ac8125f4fe3d0b1aff64b7964f9ad 100644 (file)
@@ -75,7 +75,21 @@ public partial struct ReagentId : IEquatable<ReagentId>
 
     public override int GetHashCode()
     {
-        return HashCode.Combine(Prototype, Data);
+        // We need to make sure we take the hash code of Data by value in order
+        // for hashed key lookups to work properly
+        var hash = 17;
+        unchecked
+        {
+            if (Data?.Count != 0)
+            {
+                foreach (var data in Data ?? [])
+                {
+                    hash = hash * 23 + data.GetHashCode();
+                }
+            }
+        }
+
+        return HashCode.Combine(Prototype, hash);
     }
 
     public string ToString(FixedPoint2 quantity)