[master] 616c1ee Speed up VSB_bcat()

Federico G. Schwindt fgsch at lodoss.net
Tue Dec 15 16:46:56 CET 2015


commit 616c1ee573e4e1a0b98918acaee75f3d7e681bf9
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date:   Tue Dec 15 15:24:26 2015 +0000

    Speed up VSB_bcat()
    
    Rather than copying one char at the time extend the buffer as needed and
    use memcpy.

diff --git a/lib/libvarnish/vsb.c b/lib/libvarnish/vsb.c
index 92abdf2..ad98c8a 100644
--- a/lib/libvarnish/vsb.c
+++ b/lib/libvarnish/vsb.c
@@ -278,20 +278,20 @@ VSB_put_byte(struct vsb *s, int c)
 int
 VSB_bcat(struct vsb *s, const void *buf, size_t len)
 {
-	const char *str = buf;
-	const char *end = str + len;
-
 	assert_VSB_integrity(s);
 	assert_VSB_state(s, 0);
 
 	if (s->s_error != 0)
 		return (-1);
 	_vsb_indent(s);
-	for (; str < end; str++) {
-		VSB_put_byte(s, *str);
+	if (len > VSB_FREESPACE(s)) {
+		if (VSB_extend(s, len - VSB_FREESPACE(s)) < 0)
+			s->s_error = ENOMEM;
 		if (s->s_error != 0)
 			return (-1);
 	}
+	memcpy(s->s_buf + s->s_len, buf, len);
+	s->s_len += len;
 	return (0);
 }
 



More information about the varnish-commit mailing list