From 6669d22e3784a5b1ad46307908e0b6c072cc1c26 Mon Sep 17 00:00:00 2001 From: zhaozhibo Date: Tue, 18 Jan 2022 14:57:19 +0800 Subject: [PATCH] add 'utf8Len' parameter for 'CanBeCompressed()' Signed-off-by: zhaozhibo --- ecmascript/ecma_string.cpp | 3 --- ecmascript/ecma_string.h | 2 +- ecmascript/object_factory.cpp | 9 ++++++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ecmascript/ecma_string.cpp b/ecmascript/ecma_string.cpp index eef2e685bd..798820b285 100644 --- a/ecmascript/ecma_string.cpp +++ b/ecmascript/ecma_string.cpp @@ -246,9 +246,6 @@ bool EcmaString::CanBeCompressed(const uint8_t *utf8Data, uint32_t utf8Len) } bool isCompressed = true; uint32_t index = 0; - if (utf8Len == UINT32_MAX) { - utf8Len = strlen((const char *)utf8Data); - } // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) while (index < utf8Len) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) diff --git a/ecmascript/ecma_string.h b/ecmascript/ecma_string.h index 2b1b090bef..b3d5cd3ef1 100644 --- a/ecmascript/ecma_string.h +++ b/ecmascript/ecma_string.h @@ -260,7 +260,7 @@ public: static EcmaString *AllocStringObject(size_t length, bool compressed, const EcmaVM *vm); - static bool CanBeCompressed(const uint8_t *utf8Data, uint32_t utf8Len = UINT32_MAX); + static bool CanBeCompressed(const uint8_t *utf8Data, uint32_t utf8Len); static bool CanBeCompressed(const uint16_t *utf16Data, uint32_t utf16Len); private: diff --git a/ecmascript/object_factory.cpp b/ecmascript/object_factory.cpp index 5cb226c927..03ee42215b 100644 --- a/ecmascript/object_factory.cpp +++ b/ecmascript/object_factory.cpp @@ -2065,21 +2065,24 @@ JSHandle ObjectFactory::NewClassInfoExtractor(JSMethod *ctor JSHandle ObjectFactory::NewFromString(const CString &data) { auto utf8Data = reinterpret_cast(data.c_str()); - bool canBeCompress = EcmaString::CanBeCompressed(utf8Data); + uint32_t utf8Len = strlen(utf8Data); + bool canBeCompress = EcmaString::CanBeCompressed(utf8Data, utf8Len); return GetStringFromStringTable(utf8Data, data.length(), canBeCompress); } JSHandle ObjectFactory::NewFromCanBeCompressString(const CString &data) { auto utf8Data = reinterpret_cast(data.c_str()); - ASSERT(EcmaString::CanBeCompressed(utf8Data)); + uint32_t utf8Len = strlen(utf8Data); + ASSERT(EcmaString::CanBeCompressed(utf8Data, utf8Len)); return GetStringFromStringTable(utf8Data, data.length(), true); } JSHandle ObjectFactory::NewFromStdString(const std::string &data) { auto utf8Data = reinterpret_cast(data.c_str()); - bool canBeCompress = EcmaString::CanBeCompressed(utf8Data); + uint32_t utf8Len = strlen(utf8Data); + bool canBeCompress = EcmaString::CanBeCompressed(utf8Data, utf8Len); return GetStringFromStringTable(utf8Data, data.size(), canBeCompress); }