aboutsummaryrefslogtreecommitdiffstats
path: root/pb_encode.c
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-02-05 22:06:36 +0200
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-02-05 22:06:36 +0200
commitc372ebc665540df2578e869e73405b3d309bfc48 (patch)
tree5ca9089c5aa273ac289febef43e1fe20541c896d /pb_encode.c
parent38ced18639f1e2236e9949071e3ddc148cf2ad73 (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_encode.c')
-rw-r--r--pb_encode.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/pb_encode.c b/pb_encode.c
index 5d1965d1..95223cb6 100644
--- a/pb_encode.c
+++ b/pb_encode.c
@@ -37,8 +37,11 @@ static const pb_encoder_t PB_ENCODERS[PB_LTYPES_COUNT] = {
static bool checkreturn buf_write(pb_ostream_t *stream, const uint8_t *buf, size_t count)
{
uint8_t *dest = (uint8_t*)stream->state;
- memcpy(dest, buf, count);
stream->state = dest + count;
+
+ while (count--)
+ *dest++ = *buf++;
+
return true;
}