Refactor jrt buffer operations

`jrt_read_from_buffer_by_offset` is not used anywhere in the code
while `jrt_write_to_buffer_by_offset` is only used by snapshot
saving functions. Thus, this patch removes the read variant
completely and moves the write variant as a static function to
jerry.c. This empties out jrt.c, thus deleting.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
Akos Kiss
2016-08-04 15:27:05 +02:00
parent 697442434d
commit e9a23c4235
3 changed files with 43 additions and 91 deletions
-73
View File
@@ -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 */
-3
View File
@@ -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 */