Skip to content

Commit f73d287

Browse files
committed
[WIP] Try to reduce binary size
JerryScript-DCO-1.0-Signed-off-by: László Langó [email protected]
1 parent 6fce323 commit f73d287

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

jerry-core/ecma/base/ecma-helpers-string.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,6 +2181,30 @@ ecma_string_trim (const ecma_string_t *string_p) /**< pointer to an ecma string
21812181
return ret_string_p;
21822182
} /* ecma_string_trim */
21832183

2184+
/**
2185+
* Helper function for ecma_string conversion. It is used in
2186+
* ECMA_STRING_TO_UTF8_STRING macro. Returns true if the output
2187+
* buffer must be freed.
2188+
*
2189+
* @return true - if the output buffer must be freed.
2190+
* false - otherwise
2191+
*/
2192+
bool ecma_string_to_utf8_string (const ecma_string_t *ecma_str_ptr, /**< ecma string pointer */
2193+
const lit_utf8_byte_t **utf8_ptr, /**< [out] output buffer pointer */
2194+
lit_utf8_size_t *utf8_str_size) /**< [out] output buffer size */
2195+
{
2196+
*utf8_ptr = ecma_string_get_chars (ecma_str_ptr, utf8_str_size, NULL);
2197+
2198+
if (*utf8_ptr == NULL)
2199+
{
2200+
*utf8_ptr = (const lit_utf8_byte_t *) jmem_heap_alloc_block (*utf8_str_size);
2201+
ecma_string_to_utf8_bytes (ecma_str_ptr, (lit_utf8_byte_t *) *utf8_ptr, *utf8_str_size);
2202+
return true;
2203+
}
2204+
2205+
return false;
2206+
} /* ecma_string_to_utf8_string*/
2207+
21842208
/**
21852209
* @}
21862210
* @}

jerry-core/ecma/base/ecma-helpers.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,19 @@
5050
*/
5151
#define ECMA_SET_POINTER(field, non_compressed_pointer) JMEM_CP_SET_POINTER (field, non_compressed_pointer)
5252

53+
bool ecma_string_to_utf8_string (const ecma_string_t *ecma_str_ptr,
54+
const lit_utf8_byte_t **utf8_ptr,
55+
lit_utf8_size_t *utf8_str_size);
56+
5357
/**
5458
* Convert ecma-string's contents to a cesu-8 string and put it into a buffer.
5559
*/
5660
#define ECMA_STRING_TO_UTF8_STRING(ecma_str_ptr, /**< ecma string pointer */ \
5761
utf8_ptr, /**< [out] output buffer pointer */ \
5862
utf8_str_size) /**< [out] output buffer size */ \
5963
lit_utf8_size_t utf8_str_size; \
60-
const lit_utf8_byte_t *utf8_ptr = ecma_string_get_chars (ecma_str_ptr, &utf8_str_size, NULL); \
61-
bool utf8_ptr ## must_be_freed = false; \
62-
\
63-
if (utf8_ptr == NULL) \
64-
{ \
65-
utf8_ptr = (const lit_utf8_byte_t *) jmem_heap_alloc_block (utf8_str_size); \
66-
ecma_string_to_utf8_bytes (ecma_str_ptr, (lit_utf8_byte_t *) utf8_ptr, utf8_str_size); \
67-
utf8_ptr ## must_be_freed = true; \
68-
}
64+
const lit_utf8_byte_t *utf8_ptr = NULL; \
65+
bool utf8_ptr ## must_be_freed = ecma_string_to_utf8_string (ecma_str_ptr, &utf8_ptr, &utf8_str_size);
6966

7067
#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY
7168

0 commit comments

Comments
 (0)