From 01056f369abaf4cf071c5a2e5868ad5273efed80 Mon Sep 17 00:00:00 2001 From: Fredrik Lindahl <18470258+fLindahl@users.noreply.github.com> Date: Tue, 6 May 2025 21:40:56 +0200 Subject: [PATCH] [.NET] Avoid heap allocation when using StringNames as key in a Collection.Dictionary. Changed StringName GetHashCode to call godot_string_name.GetHashCode instead of godot_string_name's (which was not overridden) as this otherwise leads to heap allocations when e.g. calling the indexer in a Dictionary with `StringName` type as Key. --- modules/mono/glue/GodotSharp/GodotSharp/Core/StringName.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/StringName.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/StringName.cs index 21d9ada1272..a28230636fd 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/StringName.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/StringName.cs @@ -161,7 +161,7 @@ namespace Godot public override int GetHashCode() { - return NativeValue.GetHashCode(); + return NativeValue.DangerousSelfRef.GetHashCode(); } } }