diff options
author | Eric Wong <e@80x24.org> | 2018-12-01 13:23:21 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2018-12-01 13:26:44 +0000 |
commit | 14e39b67a7696b1ba0875baccbb4fbc73a068b16 (patch) | |
tree | 5bb4d6a8f1b5aa2ba14818c461c6ac4a7131235f | |
parent | e2973f39f372235c2ae377d85a1c5a3c4582e967 (diff) | |
download | kcar-14e39b67a7696b1ba0875baccbb4fbc73a068b16.tar.gz |
Ruby 2.6 will unconditionally dedupe all hash key strings thanks to Anmol Chopra at https://bugs.ruby-lang.org/issues/15251
-rw-r--r-- | ext/kcar/extconf.rb | 11 | ||||
-rw-r--r-- | ext/kcar/kcar.rl | 5 |
2 files changed, 14 insertions, 2 deletions
diff --git a/ext/kcar/extconf.rb b/ext/kcar/extconf.rb index b65846a..ba69c3c 100644 --- a/ext/kcar/extconf.rb +++ b/ext/kcar/extconf.rb @@ -22,4 +22,15 @@ rescue NoMethodError message("no, String#-@ not available\n") end +message('checking if Hash#[]= (rb_hash_aset) dedupes... ') +h = {} +h[%w(m k m f).join('')] = :foo +if 'mkmf'.freeze.equal?(h.keys[0]) + $CPPFLAGS += ' -DHASH_ASET_DEDUPE=1 ' + message("yes\n") +else + $CPPFLAGS += ' -DHASH_ASET_DEDUPE=0 ' + message("no, needs Ruby 2.6+\n") +end + create_makefile("kcar_ext") diff --git a/ext/kcar/kcar.rl b/ext/kcar/kcar.rl index 336af55..9d04dd8 100644 --- a/ext/kcar/kcar.rl +++ b/ext/kcar/kcar.rl @@ -489,7 +489,6 @@ static void write_response_value(struct http_parser *hp, VALUE hdr, } } -/* TODO cache */ static VALUE req_field(const char *ptr, size_t len) { size_t pfxlen = sizeof("HTTP_") - 1; @@ -501,7 +500,7 @@ static VALUE req_field(const char *ptr, size_t len) assert(*(dst + RSTRING_LEN(str)) == '\0' && "string didn't end with \\0"); /* paranoia */ - return str_dd_freeze(str); + return str; } static void snake_upcase(char *ptr, size_t len) @@ -570,6 +569,8 @@ static void write_request_value(struct http_parser *hp, VALUE env, hp->v.host = val; } else { key = req_field(fptr, flen); + if (!HASH_ASET_DEDUPE) + key = str_dd_freeze(key); } existing = rb_hash_aref(env, key); if (NIL_P(existing)) { |