diff options
author | Eric Wong <e@80x24.org> | 2015-05-29 05:59:27 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2015-05-29 05:59:27 +0000 |
commit | 32fefc5742d1646d63a119b281baefcac551dfec (patch) | |
tree | 41b25363661184ad338666ea978ab31f9f2992f1 /ext/unicorn_http/unicorn_http.rl | |
parent | 3f0b69e8557875eeb98e1eaeb097bf3607fa8e69 (diff) | |
download | unicorn-32fefc5742d1646d63a119b281baefcac551dfec.tar.gz |
Calling the function directly avoids the overhead of Ruby method table lookup and global method cache. The only downside is this is now hidden from tracers and cannot be overridden from Ruby, but I doubt anybody cares about that.
Diffstat (limited to 'ext/unicorn_http/unicorn_http.rl')
-rw-r--r-- | ext/unicorn_http/unicorn_http.rl | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/ext/unicorn_http/unicorn_http.rl b/ext/unicorn_http/unicorn_http.rl index 4254540..bd45dd0 100644 --- a/ext/unicorn_http/unicorn_http.rl +++ b/ext/unicorn_http/unicorn_http.rl @@ -60,7 +60,19 @@ struct http_parser { } len; }; -static ID id_clear, id_set_backtrace, id_response_start_sent; +static ID id_set_backtrace, id_response_start_sent; + +#ifdef HAVE_RB_HASH_CLEAR /* Ruby >= 2.0 */ +# define my_hash_clear(h) (void)rb_hash_clear(h) +#else /* !HAVE_RB_HASH_CLEAR - Ruby <= 1.9.3 */ + +static ID id_clear; + +static void my_hash_clear(VALUE h) +{ + rb_funcall(h, id_clear, 0); +} +#endif /* HAVE_RB_HASH_CLEAR */ static void finalize_header(struct http_parser *hp); @@ -584,7 +596,7 @@ static VALUE HttpParser_clear(VALUE self) struct http_parser *hp = data_get(self); http_parser_init(hp); - rb_funcall(hp->env, id_clear, 0); + my_hash_clear(hp->env); rb_ivar_set(self, id_response_start_sent, Qfalse); return self; @@ -926,9 +938,12 @@ void Init_unicorn_http(void) SET_GLOBAL(g_http_transfer_encoding, "TRANSFER_ENCODING"); SET_GLOBAL(g_content_length, "CONTENT_LENGTH"); SET_GLOBAL(g_http_connection, "CONNECTION"); - id_clear = rb_intern("clear"); id_set_backtrace = rb_intern("set_backtrace"); id_response_start_sent = rb_intern("@response_start_sent"); init_unicorn_httpdate(); + +#ifndef HAVE_RB_HASH_CLEAR + id_clear = rb_intern("clear"); +#endif } #undef SET_GLOBAL |