From 99c35bb21639a4d9e4d3da7434960525d2113ac2 Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Tue, 28 Sep 2004 11:02:18 +0000 Subject: [PATCH] Change buffer_put/fetchchar functions to use memcpy. We used an inefficient loop to copy data in the buffer character functions; change them to use memcpy. --- charfuncs.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/charfuncs.c b/charfuncs.c index c8a140f..778df1c 100644 --- a/charfuncs.c +++ b/charfuncs.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -22,12 +23,11 @@ int buffer_fetchchar(void *ctx, size_t count, unsigned char *c) { struct buffer_ctx *buf = NULL; - size_t i; buf = (struct buffer_ctx *) ctx; - for (i = 0; i < count; i++) { - c[i] = buf->buffer[buf->offset++]; - } + + memcpy(c, &buf->buffer[buf->offset], count); + buf->offset += count; return (((buf->offset) == (buf->size)) ? 1 : 0); } @@ -46,7 +46,6 @@ int buffer_putchar(void *ctx, size_t count, unsigned char *c) { struct buffer_ctx *buf = NULL; size_t newsize = 0; - size_t i; buf = (struct buffer_ctx *) ctx; @@ -57,11 +56,10 @@ int buffer_putchar(void *ctx, size_t count, unsigned char *c) buf->buffer = realloc(buf->buffer, newsize); buf->size = newsize; } - - for (i = 0; i < count; i++) { - buf->buffer[buf->offset++] = c[i]; - } + memcpy(&buf->buffer[buf->offset], c, count); + buf->offset += count; + return 1; } -- 2.39.5