diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-06-13 22:35:18 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-06-13 22:35:18 +0000 |
commit | 131c241840990753f7b75344092058ef7434ea8b (patch) | |
tree | 2baa2649ead4249c38925bb709eeadeaaa132d6b /ext/unicorn_http | |
parent | 4aa8fd1322ccb46fc58a4f26ca111a03c1720c7d (diff) | |
download | unicorn-131c241840990753f7b75344092058ef7434ea8b.tar.gz |
copy-on-write behavior doesn't help you if your common use case triggers copies.
Diffstat (limited to 'ext/unicorn_http')
-rw-r--r-- | ext/unicorn_http/unicorn_http.rl | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/ext/unicorn_http/unicorn_http.rl b/ext/unicorn_http/unicorn_http.rl index b6319df..106cc6b 100644 --- a/ext/unicorn_http/unicorn_http.rl +++ b/ext/unicorn_http/unicorn_http.rl @@ -908,6 +908,13 @@ static VALUE HttpParser_filter_body(VALUE self, VALUE dst, VALUE src) if (hp->len.content > 0) { long nr = MIN(srclen, hp->len.content); + /* + * using rb_str_replace() to avoid memcpy() doesn't help in + * most cases because a GC-aware programmer will pass an explicit + * buffer to env["rack.input"].read and reuse the buffer in a loop. + * This causes copy-on-write behavior to be triggered anyways + * when the +src+ buffer is modified (when reading off the socket). + */ hp->buf = src; memcpy(RSTRING_PTR(dst), srcptr, nr); hp->len.content -= nr; |