Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Lua Json
Commits
e59ca80a
Commit
e59ca80a
authored
May 27, 2019
by
seny
Browse files
encodeByte: avoid 'memcpy'
parent
fb96e356
Changes
1
Show whitespace changes
Inline
Side-by-side
src/json-encode.c
View file @
e59ca80a
...
@@ -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
)
{
encode
Data
(
L
,
box
,
&
val
,
1
)
;
*
append
Data
(
L
,
box
,
1
)
=
val
;
}
}
static
void
encodeString
(
lua_State
*
L
,
Box
*
box
,
int
idx
)
{
static
void
encodeString
(
lua_State
*
L
,
Box
*
box
,
int
idx
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment