From baac70c27efb661e2d3f4127210e7ec991793078 Mon Sep 17 00:00:00 2001 From: zaevi Date: Sun, 31 Jan 2021 20:39:17 +0800 Subject: [PATCH] Fix C# string.Hash() --- .../GodotSharp/Core/StringExtensions.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs index 4dc182fb730..98efa89ef0a 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs @@ -462,18 +462,18 @@ namespace Godot } // - // Hash the string and return a 32 bits integer. + // Hash the string and return a 32 bits unsigned integer. // - public static int Hash(this string instance) + public static uint Hash(this string instance) { - int index = 0; - int hashv = 5381; - int c; + uint hash = 5381; - while ((c = instance[index++]) != 0) - hashv = (hashv << 5) + hashv + c; // hash * 33 + c + foreach(uint c in instance) + { + hash = (hash << 5) + hash + c; // hash * 33 + c + } - return hashv; + return hash; } ///