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_decode.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_decode.c')
-rw-r--r-- | pb_decode.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/pb_decode.c b/pb_decode.c index 9faceca..b664fe1 100644 --- a/pb_decode.c +++ b/pb_decode.c @@ -52,6 +52,7 @@ static bool checkreturn buf_read(pb_istream_t *stream, uint8_t *buf, size_t coun bool checkreturn pb_read(pb_istream_t *stream, uint8_t *buf, size_t count) { +#ifndef PB_BUFFER_ONLY if (buf == NULL && stream->callback != buf_read) { /* Skip input bytes */ @@ -66,12 +67,18 @@ bool checkreturn pb_read(pb_istream_t *stream, uint8_t *buf, size_t count) return pb_read(stream, tmp, count); } +#endif if (stream->bytes_left < count) PB_RETURN_ERROR(stream, "end-of-stream"); +#ifndef PB_BUFFER_ONLY if (!stream->callback(stream, buf, count)) PB_RETURN_ERROR(stream, "io error"); +#else + if (!buf_read(stream, buf, count)) + return false; +#endif stream->bytes_left -= count; return true; @@ -80,7 +87,11 @@ bool checkreturn pb_read(pb_istream_t *stream, uint8_t *buf, size_t count) pb_istream_t pb_istream_from_buffer(uint8_t *buf, size_t bufsize) { pb_istream_t stream; +#ifdef PB_BUFFER_ONLY + stream.callback = NULL; +#else stream.callback = &buf_read; +#endif stream.state = buf; stream.bytes_left = bufsize; #ifndef PB_NO_ERRMSG |