]> the.earth.li Git - onak.git/commitdiff
Change buffer_put/fetchchar functions to use memcpy.
authorJonathan McDowell <noodles@earth.li>
Tue, 28 Sep 2004 11:02:18 +0000 (11:02 +0000)
committerJonathan McDowell <noodles@earth.li>
Tue, 28 Sep 2004 11:02:18 +0000 (11:02 +0000)
We used an inefficient loop to copy data in the buffer character
functions; change them to use memcpy.

charfuncs.c

index c8a140ff2ff45686cac6804c522a83e033a70e62..778df1ca477732fac168895fc3094e45af329ae4 100644 (file)
@@ -7,6 +7,7 @@
  */
 
 #include <stdio.h>
+#include <string.h>
 #include <sys/types.h>
 #include <sys/uio.h>
 #include <unistd.h>
 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;
 }