From 131c241840990753f7b75344092058ef7434ea8b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 13 Jun 2011 22:35:18 +0000 Subject: http: document reasoning for memcpy in filter_body copy-on-write behavior doesn't help you if your common use case triggers copies. --- ext/unicorn_http/unicorn_http.rl | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'ext') 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; -- cgit v1.2.3-24-ge0c7