diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-06-15 00:20:26 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-06-15 00:20:26 +0000 |
commit | 12024a6268d4e96fcf96df33fb7d82eaec9c16b1 (patch) | |
tree | 68c2b498e228b9809d9c5af220f840b9a8f7075b /ext/unicorn_http/unicorn_http.rl | |
parent | d91ca210615432bdad3ee70c08908ea7064c6b95 (diff) | |
download | unicorn-12024a6268d4e96fcf96df33fb7d82eaec9c16b1.tar.gz |
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.
Diffstat (limited to 'ext/unicorn_http/unicorn_http.rl')
-rw-r--r-- | ext/unicorn_http/unicorn_http.rl | 8 |
1 files changed, 5 insertions, 3 deletions
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; } } |