From b58ac4027eaaab42554cfa37d68a65b0192d1ca3 Mon Sep 17 00:00:00 2001 From: Sergei Shadrin Date: Wed, 31 Aug 2022 17:23:48 +0000 Subject: [PATCH] ComputeHashcodeUtf8 optimization Change-Id: I50bfddde7a9642a93aa4ed27196475f8a92ef688 Signed-off-by: Sergei Shadrin --- runtime/ecma_string.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/runtime/ecma_string.cpp b/runtime/ecma_string.cpp index 8b6d085c3..b784b485f 100644 --- a/runtime/ecma_string.cpp +++ b/runtime/ecma_string.cpp @@ -411,11 +411,12 @@ uint32_t EcmaString::ComputeHashcodeUtf8(const uint8_t *utf8Data, size_t utf8Len if (canBeCompress) { hash = ComputeHashForUtf8(utf8Data); } else { - auto utf16Len = base::utf_helper::Utf8ToUtf16Size(utf8Data, utf8Len); + // utf8len >= utf16len for equal strings + auto utf16Len = utf8Len; PandaVector tmpBuffer(utf16Len); [[maybe_unused]] auto len = base::utf_helper::ConvertRegionUtf8ToUtf16(utf8Data, tmpBuffer.data(), utf8Len, utf16Len, 0); - ASSERT(len == utf16Len); + ASSERT(len == base::utf_helper::Utf8ToUtf16Size(utf8Data, utf8Len)); hash = ComputeHashForData(tmpBuffer.data(), utf16Len); } return hash; -- Gitee