add 'utf8Len' parameter for 'CanBeCompressed()'

Signed-off-by: zhaozhibo <zhaozhibo3@huawei.com>
This commit is contained in:
zhaozhibo 2022-01-18 14:57:19 +08:00
parent 55e79d9150
commit 6669d22e37
3 changed files with 7 additions and 7 deletions

View File

@ -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)

View File

@ -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:

View File

@ -2065,21 +2065,24 @@ JSHandle<ClassInfoExtractor> ObjectFactory::NewClassInfoExtractor(JSMethod *ctor
JSHandle<EcmaString> ObjectFactory::NewFromString(const CString &data)
{
auto utf8Data = reinterpret_cast<const uint8_t *>(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<EcmaString> ObjectFactory::NewFromCanBeCompressString(const CString &data)
{
auto utf8Data = reinterpret_cast<const uint8_t *>(data.c_str());
ASSERT(EcmaString::CanBeCompressed(utf8Data));
uint32_t utf8Len = strlen(utf8Data);
ASSERT(EcmaString::CanBeCompressed(utf8Data, utf8Len));
return GetStringFromStringTable(utf8Data, data.length(), true);
}
JSHandle<EcmaString> ObjectFactory::NewFromStdString(const std::string &data)
{
auto utf8Data = reinterpret_cast<const uint8_t *>(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);
}