Browse Source

printbuf: append single-byte values directly

Do not call memcpy for single-byte values, as writing them directly
involves fewer overhead and thus is faster. Verified effect with
valgrind's callgrind profiler and wallclock timing.
pull/208/head
Rainer Gerhards 10 years ago
parent
commit
6a6278c298
1 changed files with 4 additions and 1 deletions
  1. +4
    -1
      printbuf.c

+ 4
- 1
printbuf.c View File

@@ -83,7 +83,10 @@ int printbuf_memappend(struct printbuf *p, const char *buf, int size)
if (printbuf_extend(p, p->bpos + size + 1) < 0)
return -1;
}
memcpy(p->buf + p->bpos, buf, size);
if(size > 1)
memcpy(p->buf + p->bpos, buf, size);
else
p->buf[p->bpos]= *buf;
p->bpos += size;
p->buf[p->bpos]= '\0';
return size;


Loading…
Cancel
Save