about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-06-13 22:35:18 +0000
committerEric Wong <normalperson@yhbt.net>2011-06-13 22:35:18 +0000
commit131c241840990753f7b75344092058ef7434ea8b (patch)
tree2baa2649ead4249c38925bb709eeadeaaa132d6b
parent4aa8fd1322ccb46fc58a4f26ca111a03c1720c7d (diff)
downloadunicorn-131c241840990753f7b75344092058ef7434ea8b.tar.gz
copy-on-write behavior doesn't help you if your common
use case triggers copies.
-rw-r--r--ext/unicorn_http/unicorn_http.rl7
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;