Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
c5287b90
Commit
c5287b90
authored
Apr 09, 2014
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
iobuf_append() refactored: allocating exactly as many bytes as needed
parent
223f6d96
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
10 deletions
+5
-10
mongoose.c
mongoose.c
+5
-10
No files found.
mongoose.c
View file @
c5287b90
...
...
@@ -266,10 +266,6 @@ int ns_hexdump(const void *buf, int len, char *dst, int dst_len);
#define NS_FREE free
#endif
#ifndef IOBUF_RESIZE_MULTIPLIER
#define IOBUF_RESIZE_MULTIPLIER 2.0
#endif
void
iobuf_init
(
struct
iobuf
*
iobuf
,
size_t
size
)
{
iobuf
->
len
=
iobuf
->
size
=
0
;
iobuf
->
buf
=
NULL
;
...
...
@@ -288,19 +284,18 @@ void iobuf_free(struct iobuf *iobuf) {
size_t
iobuf_append
(
struct
iobuf
*
io
,
const
void
*
buf
,
size_t
len
)
{
char
*
p
=
NULL
;
size_t
new_len
=
io
->
len
+
len
,
new_size
=
new_len
*
IOBUF_RESIZE_MULTIPLIER
;
assert
(
io
->
len
<=
io
->
size
);
if
(
len
<=
0
)
{
}
else
if
(
new_len
<
io
->
size
)
{
}
else
if
(
io
->
len
+
len
<=
io
->
size
)
{
memcpy
(
io
->
buf
+
io
->
len
,
buf
,
len
);
io
->
len
=
new_
len
;
}
else
if
((
p
=
(
char
*
)
NS_REALLOC
(
io
->
buf
,
new_size
))
!=
NULL
)
{
io
->
len
+=
len
;
}
else
if
((
p
=
(
char
*
)
NS_REALLOC
(
io
->
buf
,
io
->
len
+
len
))
!=
NULL
)
{
io
->
buf
=
p
;
memcpy
(
io
->
buf
+
io
->
len
,
buf
,
len
);
io
->
len
=
new_
len
;
io
->
size
=
new_size
;
io
->
len
+=
len
;
io
->
size
=
io
->
len
;
}
else
{
len
=
0
;
}
...
...
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