From 16cbe0c63b52d806ecfe56c2f60cb6b5f19af734 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Thu, 28 Aug 2014 21:19:44 +0400 Subject: [PATCH] Removing try_get_string_by_idx and get_number_by_idx. --- src/libcoreint/interpreter.c | 46 ------------------------ src/libcoreint/interpreter.h | 3 -- src/libcoreint/opcodes.c | 6 ++-- src/libecmaobjects/ecma-helpers-string.c | 25 ++++++------- src/libecmaobjects/ecma-helpers.h | 2 +- 5 files changed, 17 insertions(+), 65 deletions(-) diff --git a/src/libcoreint/interpreter.c b/src/libcoreint/interpreter.c index c156f7209..9bef09dbf 100644 --- a/src/libcoreint/interpreter.c +++ b/src/libcoreint/interpreter.c @@ -13,7 +13,6 @@ * limitations under the License. */ -#include "deserializer.h" #include "ecma-gc.h" #include "ecma-globals.h" #include "ecma-global-object.h" @@ -190,51 +189,6 @@ run_int_from_pos (opcode_counter_t start_pos, return completion; } -/** - * Copy zero-terminated string literal value to specified buffer. - * - * @return upon success - number of bytes actually copied, - * otherwise (buffer size is not enough) - negated minimum required buffer size. - */ -ssize_t -try_get_string_by_idx (idx_t idx, /**< literal id */ - ecma_char_t *buffer_p, /**< buffer */ - ssize_t buffer_size) /**< buffer size */ -{ - const ecma_char_t *str_p = deserialize_string_by_id (idx); - JERRY_ASSERT (str_p != NULL); - - FIXME (ecma_char_t strlen); - - ssize_t req_length = (ssize_t)__strlen ((const char*)str_p) + 1; - - if (buffer_size < req_length) - { - return -req_length; - } - - FIXME (ecma_char_t strncpy); - - JERRY_ASSERT (buffer_p != NULL); - - __strncpy ((char*)buffer_p, (const char*)str_p, (size_t)req_length); - - return req_length; -} /* try_get_string_by_idx */ - -/** - * Get number literal value. - * - * @return value of number literal, corresponding to specified literal id - */ -ecma_number_t -get_number_by_idx (idx_t idx) /**< literal id */ -{ - ecma_number_t num = deserialize_num_by_id (idx); - - return num; -} /* get_number_by_idx */ - /** * Get specified opcode from the program. */ diff --git a/src/libcoreint/interpreter.h b/src/libcoreint/interpreter.h index 50ab09b08..21890da67 100644 --- a/src/libcoreint/interpreter.h +++ b/src/libcoreint/interpreter.h @@ -29,9 +29,6 @@ ecma_completion_value_t run_int_from_pos (opcode_counter_t start_pos, bool is_strict, bool is_eval_code); -ssize_t try_get_string_by_idx (idx_t idx, ecma_char_t *buffer_p, ssize_t buffer_size); -ecma_number_t get_number_by_idx (idx_t idx); - opcode_t read_opcode (opcode_counter_t counter); #endif /* INTERPRETER_H */ diff --git a/src/libcoreint/opcodes.c b/src/libcoreint/opcodes.c index 79b59a84d..e737f007a 100644 --- a/src/libcoreint/opcodes.c +++ b/src/libcoreint/opcodes.c @@ -13,11 +13,11 @@ * limitations under the License. */ -#include "opcodes-ecma-support.h" - +#include "deserializer.h" #include "globals.h" #include "interpreter.h" #include "opcodes.h" +#include "opcodes-ecma-support.h" /** * Note: @@ -159,7 +159,7 @@ opfunc_assignment (opcode_t opdata, /**< operation data */ case OPCODE_ARG_TYPE_NUMBER: { ecma_number_t *num_p = ecma_alloc_number (); - *num_p = get_number_by_idx (src_val_descr); + *num_p = deserialize_num_by_id (src_val_descr); get_value_completion = ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, ecma_make_number_value (num_p), diff --git a/src/libecmaobjects/ecma-helpers-string.c b/src/libecmaobjects/ecma-helpers-string.c index 72b08a172..80a0f05e9 100644 --- a/src/libecmaobjects/ecma-helpers-string.c +++ b/src/libecmaobjects/ecma-helpers-string.c @@ -173,12 +173,12 @@ ecma_new_ecma_string_from_lit_index (literal_index_t lit_index) /**< ecma-number ecma_string_t* string_desc_p = ecma_alloc_string (); string_desc_p->refs = 1; - FIXME (/* Interface for getting literal's length */); + FIXME (/* Interface for getting literal's length without string's characters iteration */); + const ecma_char_t *str_p = deserialize_string_by_id ((idx_t) lit_index); + JERRY_ASSERT (str_p != NULL); + ecma_length_t length = (ecma_length_t) __strlen ((const char*)str_p); - ssize_t size_required = try_get_string_by_idx ((uint8_t) lit_index, NULL, 0); - JERRY_ASSERT (size_required < 0); - - string_desc_p->length = (ecma_length_t) ((size_t)-size_required / sizeof (ecma_char_t) - 1); + string_desc_p->length = length; string_desc_p->container = ECMA_STRING_CONTAINER_LIT_TABLE; string_desc_p->u.lit_index = lit_index; @@ -425,10 +425,12 @@ ecma_string_to_zt_string (const ecma_string_t *string_desc_p, /**< ecma-string d } case ECMA_STRING_CONTAINER_LIT_TABLE: { - bytes_copied = try_get_string_by_idx ((uint8_t) string_desc_p->u.lit_index, - buffer_p, - buffer_size); + const ecma_char_t *str_p = deserialize_string_by_id ((idx_t) string_desc_p->u.lit_index); + JERRY_ASSERT (str_p != NULL); + __strncpy ((char*)buffer_p, (const char*)str_p, string_desc_p->length + 1u); + JERRY_ASSERT (__strlen ((char*)buffer_p) == string_desc_p->length); + bytes_copied = (ssize_t) ((string_desc_p->length + 1u) * sizeof (ecma_char_t)); break; } case ECMA_STRING_CONTAINER_UINT32_IN_DESC: @@ -758,11 +760,10 @@ ecma_compare_ecma_string_to_ecma_string (const ecma_string_t *string1_p, /* ecma /** * Compare zero-terminated string to zero-terminated string * - * @return 0 - if strings are equal; - * -1 - if first string is lexicographically less than second; - * 1 - otherwise. + * @return true - if strings are equal; + * false - otherwise. */ -int32_t +bool ecma_compare_zt_string_to_zt_string (const ecma_char_t *string1_p, /**< zero-terminated string */ const ecma_char_t *string2_p) /**< zero-terminated string */ { diff --git a/src/libecmaobjects/ecma-helpers.h b/src/libecmaobjects/ecma-helpers.h index 9f30ddcbb..0d9f290d2 100644 --- a/src/libecmaobjects/ecma-helpers.h +++ b/src/libecmaobjects/ecma-helpers.h @@ -98,7 +98,7 @@ extern ecma_number_t ecma_string_to_number (const ecma_string_t *str_p); extern ssize_t ecma_string_to_zt_string (const ecma_string_t *string_desc_p, ecma_char_t *buffer_p, ssize_t buffer_size); -extern int32_t ecma_compare_zt_string_to_zt_string (const ecma_char_t *string1_p, const ecma_char_t *string2_p); +extern bool ecma_compare_zt_string_to_zt_string (const ecma_char_t *string1_p, const ecma_char_t *string2_p); extern bool ecma_compare_ecma_string_to_ecma_string (const ecma_string_t *string1_p, const ecma_string_t *string2_p);