diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2013-02-06 20:54:25 +0200 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2013-02-06 20:54:25 +0200 |
commit | 4ba6a3027d7a5d8c17abeb031622389f8be234fe (patch) | |
tree | 3c2fdba47e9b9c11a0e3b0996c9f733abb4c07c1 /pb_encode.c | |
parent | 39b8a5e2bbd5da85f23b48280e81a5ce6672b09d (diff) |
Add compile-time option PB_BUFFER_ONLY.
This allows slight optimizations if only memory buffer support
(as opposed to stream callbacks) is wanted. On ARM difference
is -12% execution time, -4% code size when enabled.
Diffstat (limited to 'pb_encode.c')
-rw-r--r-- | pb_encode.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/pb_encode.c b/pb_encode.c index 95223cb6..bba5dc19 100644 --- a/pb_encode.c +++ b/pb_encode.c @@ -48,7 +48,11 @@ static bool checkreturn buf_write(pb_ostream_t *stream, const uint8_t *buf, size pb_ostream_t pb_ostream_from_buffer(uint8_t *buf, size_t bufsize) { pb_ostream_t stream; +#ifdef PB_BUFFER_ONLY + stream.callback = (void*)1; /* Just some marker value */ +#else stream.callback = &buf_write; +#endif stream.state = buf; stream.max_size = bufsize; stream.bytes_written = 0; @@ -61,9 +65,14 @@ bool checkreturn pb_write(pb_ostream_t *stream, const uint8_t *buf, size_t count { if (stream->bytes_written + count > stream->max_size) return false; - + +#ifdef PB_BUFFER_ONLY + if (!buf_write(stream, buf, count)) + return false; +#else if (!stream->callback(stream, buf, count)) return false; +#endif } stream->bytes_written += count; |