diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2013-02-05 22:06:36 +0200 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2013-02-05 22:06:36 +0200 |
commit | c372ebc665540df2578e869e73405b3d309bfc48 (patch) | |
tree | 5ca9089c5aa273ac289febef43e1fe20541c896d /pb_decode.c | |
parent | 38ced18639f1e2236e9949071e3ddc148cf2ad73 (diff) |
Performance improvement: replace memcpy with loop.
In the pb_istream_from_buffer and pb_ostream_from_buffer, memcpy was
used to transfer values to the buffer. For the common case of
count = 1-10 bytes, a simple loop is faster.
Diffstat (limited to 'pb_decode.c')
-rw-r--r-- | pb_decode.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/pb_decode.c b/pb_decode.c index 7c68b5a2..6ddde773 100644 --- a/pb_decode.c +++ b/pb_decode.c @@ -39,11 +39,14 @@ static const pb_decoder_t PB_DECODERS[PB_LTYPES_COUNT] = { static bool checkreturn buf_read(pb_istream_t *stream, uint8_t *buf, size_t count) { uint8_t *source = (uint8_t*)stream->state; + stream->state = source + count; if (buf != NULL) - memcpy(buf, source, count); + { + while (count--) + *buf++ = *source++; + } - stream->state = source + count; return true; } |