mirror of
https://github.com/Samsung/escargot.git
synced 2026-06-22 10:01:50 +00:00
* Compress CompressibleStrings on GC reclaim end event
- if there is reference about data of CompressibleString on stack, we should give up compressing.
we don't need to search heap space because I redesigned StringView
(we should not store string buffer data on heap without owner)
* Redesign StringView
- Don't save string buffer address as its member. because buffer of CompressibleString can be deleted
- If we don't save string buffer address on StringView, parser performance may dropped.
becuase parser access string data a lot.
so I introduce ParserStringView. it saves buffer address. we should ParserStringView on parser only.
we can save string buffer address while parsing. because GC is disabled while parsing.
* Enable CompressibleString always
* Implement cache of RegExpOptionStrings
* Implement finding system locale function on RuntimeICUBinder avoiding call uloc_getDefault.
Signed-off-by: Seonghyun Kim <sh8281.kim@samsung.com>
118 lines
3.4 KiB
C++
118 lines
3.4 KiB
C++
/*
|
|
* Copyright (c) 2019-present Samsung Electronics Co., Ltd
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
|
* USA
|
|
*/
|
|
|
|
#ifndef __EscargotCompressibleString__
|
|
#define __EscargotCompressibleString__
|
|
|
|
#if defined(ENABLE_COMPRESSIBLE_STRING)
|
|
|
|
#include "runtime/String.h"
|
|
|
|
namespace Escargot {
|
|
|
|
class Context;
|
|
|
|
class CompressibleString : public String {
|
|
friend class VMInstance;
|
|
|
|
public:
|
|
CompressibleString(Context* context);
|
|
|
|
// 8bit string constructor
|
|
CompressibleString(Context* context, const char* str, size_t len);
|
|
CompressibleString(Context* context, const LChar* str, size_t len);
|
|
|
|
// 16bit string constructor
|
|
CompressibleString(Context* context, const char16_t* str, size_t len);
|
|
|
|
// from already allocated buffer
|
|
CompressibleString(Context* context, void* buffer, size_t stringLength, bool is8bit);
|
|
|
|
virtual bool isCompressibleString() override
|
|
{
|
|
return true;
|
|
}
|
|
|
|
virtual UTF16StringData toUTF16StringData() const override;
|
|
virtual UTF8StringData toUTF8StringData() const override;
|
|
virtual UTF8StringDataNonGCStd toNonGCUTF8StringData() const override;
|
|
|
|
virtual const LChar* characters8() const override
|
|
{
|
|
return (const LChar*)bufferAccessData().buffer;
|
|
}
|
|
|
|
virtual const char16_t* characters16() const override
|
|
{
|
|
return (const char16_t*)bufferAccessData().buffer;
|
|
}
|
|
|
|
virtual StringBufferAccessData bufferAccessDataSpecialImpl() override
|
|
{
|
|
m_lastUsedTickcount = fastTickCount();
|
|
if (isCompressed()) {
|
|
decompress();
|
|
}
|
|
return StringBufferAccessData(m_bufferData.has8BitContent, m_bufferData.length, const_cast<void*>(m_bufferData.buffer));
|
|
}
|
|
|
|
bool isCompressed()
|
|
{
|
|
return m_isCompressed;
|
|
}
|
|
|
|
void* operator new(size_t);
|
|
void* operator new[](size_t) = delete;
|
|
void operator delete[](void*) = delete;
|
|
|
|
static void* allocateStringDataBuffer(size_t byteLength);
|
|
static void deallocateStringDataBuffer(void* ptr);
|
|
|
|
bool compress();
|
|
void decompress();
|
|
|
|
private:
|
|
void initBufferAccessData(void* data, size_t len, bool is8bit);
|
|
|
|
size_t decomressedBufferSize()
|
|
{
|
|
if (isCompressed()) {
|
|
return 0;
|
|
} else {
|
|
return m_bufferData.length * (m_bufferData.has8BitContent ? 1 : 2);
|
|
}
|
|
}
|
|
|
|
template <typename StringType>
|
|
NEVER_INLINE bool compressWorker(void* callerSP);
|
|
template <typename StringType>
|
|
NEVER_INLINE void decompressWorker();
|
|
|
|
bool m_isOwnerMayFreed;
|
|
bool m_isCompressed;
|
|
Context* m_context;
|
|
uint64_t m_lastUsedTickcount;
|
|
typedef std::vector<std::vector<char>> CompressedDataVector;
|
|
CompressedDataVector m_compressedData;
|
|
};
|
|
}
|
|
|
|
#endif // ENABLE_COMPRESSIBLE_STRING
|
|
|
|
#endif
|