Commit e59ca80a authored by seny's avatar seny
Browse files

encodeByte: avoid 'memcpy'

parent fb96e356
...@@ -32,11 +32,11 @@ typedef struct { ...@@ -32,11 +32,11 @@ typedef struct {
size_t pos, size; size_t pos, size;
} Box; } Box;
static void *resizeBox(lua_State *L, Box *box, size_t size) { static char *resizeBox(lua_State *L, Box *box, size_t size) {
void *ud; void *ud;
lua_Alloc allocf = lua_getallocf(L, &ud); lua_Alloc allocf = lua_getallocf(L, &ud);
int dyn = box->buf != box->data; /* Dynamically allocated? */ int dyn = box->buf != box->data; /* Dynamically allocated? */
void *buf = dyn ? allocf(ud, box->buf, box->size, size) : allocf(ud, 0, 0, size); char *buf = dyn ? allocf(ud, box->buf, box->size, size) : allocf(ud, 0, 0, size);
if (!size) return 0; if (!size) return 0;
if (!buf) luaL_error(L, "cannot allocate buffer"); if (!buf) luaL_error(L, "cannot allocate buffer");
if (!dyn) memcpy(buf, box->buf, box->pos); if (!dyn) memcpy(buf, box->buf, box->pos);
...@@ -63,7 +63,7 @@ static Box *newBox(lua_State *L) { ...@@ -63,7 +63,7 @@ static Box *newBox(lua_State *L) {
return box; return box;
} }
static void *appendData(lua_State *L, Box *box, size_t size) { static char *appendData(lua_State *L, Box *box, size_t size) {
char *buf = box->buf; char *buf = box->buf;
size_t pos = box->pos; size_t pos = box->pos;
size_t old = box->size; size_t old = box->size;
...@@ -81,7 +81,7 @@ static void encodeData(lua_State *L, Box *box, const char *data, size_t size) { ...@@ -81,7 +81,7 @@ static void encodeData(lua_State *L, Box *box, const char *data, size_t size) {
} }
static void encodeByte(lua_State *L, Box *box, char val) { static void encodeByte(lua_State *L, Box *box, char val) {
encodeData(L, box, &val, 1); *appendData(L, box, 1) = val;
} }
static void encodeString(lua_State *L, Box *box, int idx) { static void encodeString(lua_State *L, Box *box, int idx) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment