diff --git a/jerry-core/jerry.c b/jerry-core/jerry.c index 525fcc7c6..7ea330315 100644 --- a/jerry-core/jerry.c +++ b/jerry-core/jerry.c @@ -1747,6 +1747,34 @@ typedef struct size_t snapshot_buffer_write_offset; } snapshot_globals_t; +/** + * Write data into the specified buffer. + * + * Note: + * Offset is in-out and is incremented if the write operation completes successfully. + * + * @return true, if write was successful, i.e. offset + data_size doesn't exceed buffer size, + * false - otherwise. + */ +static inline bool __attr_always_inline___ +snapshot_write_to_buffer_by_offset (uint8_t *buffer_p, /**< buffer */ + size_t buffer_size, /**< size of buffer */ + size_t *in_out_buffer_offset_p, /**< [in,out] offset to write to + * incremented with data_size */ + const void *data_p, /**< data */ + size_t data_size) /**< size of the writable data */ +{ + if (*in_out_buffer_offset_p + data_size > buffer_size) + { + return false; + } + + memcpy (buffer_p + *in_out_buffer_offset_p, data_p, data_size); + *in_out_buffer_offset_p += data_size; + + return true; +} /* snapshot_write_to_buffer_by_offset */ + /** * Snapshot callback for byte codes. * @@ -1798,11 +1826,11 @@ snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< compiled pattern_size = buffer_size; - if (!jrt_write_to_buffer_by_offset (snapshot_buffer_p, - snapshot_buffer_size, - &globals_p->snapshot_buffer_write_offset, - buffer_p, - buffer_size)) + if (!snapshot_write_to_buffer_by_offset (snapshot_buffer_p, + snapshot_buffer_size, + &globals_p->snapshot_buffer_write_offset, + buffer_p, + buffer_size)) { globals_p->snapshot_error_occured = true; } @@ -1826,11 +1854,11 @@ snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< compiled return start_offset; } - if (!jrt_write_to_buffer_by_offset (snapshot_buffer_p, - snapshot_buffer_size, - &globals_p->snapshot_buffer_write_offset, - compiled_code_p, - ((size_t) compiled_code_p->size) << JMEM_ALIGNMENT_LOG)) + if (!snapshot_write_to_buffer_by_offset (snapshot_buffer_p, + snapshot_buffer_size, + &globals_p->snapshot_buffer_write_offset, + compiled_code_p, + ((size_t) compiled_code_p->size) << JMEM_ALIGNMENT_LOG)) { globals_p->snapshot_error_occured = true; return 0; @@ -2049,11 +2077,11 @@ jerry_parse_and_save_snapshot (const jerry_char_t *source_p, /**< script source size_t header_offset = 0; - jrt_write_to_buffer_by_offset (buffer_p, - buffer_size, - &header_offset, - &header, - sizeof (header)); + snapshot_write_to_buffer_by_offset (buffer_p, + buffer_size, + &header_offset, + &header, + sizeof (header)); if (lit_map_p != NULL) { diff --git a/jerry-core/jrt/jrt.c b/jerry-core/jrt/jrt.c deleted file mode 100644 index f13bcd6e7..000000000 --- a/jerry-core/jrt/jrt.c +++ /dev/null @@ -1,73 +0,0 @@ -/* Copyright 2016 Samsung Electronics Co., Ltd. - * Copyright 2016 University of Szeged. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "jrt.h" - -/** - * Read data from a specified buffer. - * - * Note: - * Offset is in-out and is incremented if the read operation completes successfully. - * - * @return true, if read was successful, i.e. offset + data_size doesn't exceed buffer size, - * false - otherwise. - */ -inline bool __attr_always_inline___ -jrt_read_from_buffer_by_offset (const uint8_t *buffer_p, /**< buffer */ - size_t buffer_size, /**< size of buffer */ - size_t *in_out_buffer_offset_p, /**< [in,out] offset to read from / - * incremented on sizeof (T) */ - void *out_data_p, /**< [out] data */ - size_t out_data_size) /**< size of the readable data */ -{ - if (*in_out_buffer_offset_p + out_data_size > buffer_size) - { - return false; - } - - memcpy (out_data_p, buffer_p + *in_out_buffer_offset_p, out_data_size); - *in_out_buffer_offset_p += out_data_size; - - return true; -} /* jrt_read_from_buffer_by_offset */ - -/** - * Write data to a specified buffer. - * - * Note: - * Offset is in-out and is incremented if the write operation completes successfully. - * - * @return true, if write was successful, i.e. offset + data_size doesn't exceed buffer size, - * false - otherwise. - */ -inline bool __attr_always_inline___ -jrt_write_to_buffer_by_offset (uint8_t *buffer_p, /**< buffer */ - size_t buffer_size, /**< size of buffer */ - size_t *in_out_buffer_offset_p, /**< [in,out] offset to read from / - * incremented on sizeof (T) */ - const void *data_p, /**< data */ - size_t data_size) /**< size of the writable data */ -{ - if (*in_out_buffer_offset_p + data_size > buffer_size) - { - return false; - } - - memcpy (buffer_p + *in_out_buffer_offset_p, data_p, data_size); - *in_out_buffer_offset_p += data_size; - - return true; -} /* jrt_write_to_buffer_by_offset */ diff --git a/jerry-core/jrt/jrt.h b/jerry-core/jrt/jrt.h index 2aa1883b9..fd7cf31e9 100644 --- a/jerry-core/jrt/jrt.h +++ b/jerry-core/jrt/jrt.h @@ -160,7 +160,4 @@ extern void jerry_ref_unused_variables (void *, ...); #define JERRY_MIN(v1, v2) (((v1) < (v2)) ? (v1) : (v2)) #define JERRY_MAX(v1, v2) (((v1) < (v2)) ? (v2) : (v1)) -extern bool jrt_read_from_buffer_by_offset (const uint8_t *, size_t, size_t *, void *, size_t); -extern bool jrt_write_to_buffer_by_offset (uint8_t *, size_t, size_t *, const void *, size_t); - #endif /* !JRT_H */