From 12024a6268d4e96fcf96df33fb7d82eaec9c16b1 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 15 Jun 2011 00:20:26 +0000 Subject: http: delay CoW string invalidations in filter_body Not all invocations of filter_body will trigger CoW on the given destination string. We can also avoid an unnecessary rb_str_set_len() in the non-chunked path, too. --- ext/unicorn_http/unicorn_http.rl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'ext') diff --git a/ext/unicorn_http/unicorn_http.rl b/ext/unicorn_http/unicorn_http.rl index 6a7100e..6049d9c 100644 --- a/ext/unicorn_http/unicorn_http.rl +++ b/ext/unicorn_http/unicorn_http.rl @@ -906,11 +906,12 @@ static VALUE HttpParser_filter_body(VALUE self, VALUE dst, VALUE src) srclen = RSTRING_LEN(src); StringValue(dst); - rb_str_modify(dst); - rb_str_resize(dst, srclen); /* we can never copy more than srclen bytes */ if (HP_FL_TEST(hp, CHUNKED)) { if (!chunked_eof(hp)) { + rb_str_modify(dst); + rb_str_resize(dst, srclen); /* we can never copy more than srclen bytes */ + hp->s.dest_offset = 0; hp->cont = dst; hp->buf = src; @@ -935,6 +936,8 @@ static VALUE HttpParser_filter_body(VALUE self, VALUE dst, VALUE src) if (hp->len.content > 0) { long nr = MIN(srclen, hp->len.content); + rb_str_modify(dst); + rb_str_resize(dst, nr); /* * using rb_str_replace() to avoid memcpy() doesn't help in * most cases because a GC-aware programmer will pass an explicit @@ -950,7 +953,6 @@ static VALUE HttpParser_filter_body(VALUE self, VALUE dst, VALUE src) hp->cs = http_parser_first_final; } advance_str(src, nr); - rb_str_set_len(dst, nr); src = Qnil; } } -- cgit v1.2.3-24-ge0c7