From cf041828dfa6722446e8165dd55d611815184306 Mon Sep 17 00:00:00 2001 From: liyou <303181885@qq.com> Date: Thu, 18 Dec 2025 23:29:37 +0800 Subject: [PATCH] fix result different issue --- cpp/translate/basictypes/String.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cpp/translate/basictypes/String.cpp b/cpp/translate/basictypes/String.cpp index 09d09f6..e1498ae 100644 --- a/cpp/translate/basictypes/String.cpp +++ b/cpp/translate/basictypes/String.cpp @@ -70,14 +70,18 @@ void String::setData(const char *pointer) int String::hashCode() { - int64_t h = hash; - if (hash == 0 && inner.size() > 0) { - for (size_t i = 0; i < inner.size(); ++i) { - h = static_cast(31 * h + static_cast(inner[i])); + size_t usedSize = inner.size(); + if (usedSize == 0) { + return 0; + } + int64_t hash = 0; + for (size_t i = 0; i < usedSize; ++i) { + hash = 31 * hash + static_cast(inner[i]); + if (hash > INT32_MAX || hash < INT32_MIN) { + hash = (int)hash; } - hash = static_cast(h); } - return hash; + return (int)hash; } bool String::equals(Object *obj) -- Gitee