kcar RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: kcar-public@bogomips.org
Subject: [PATCH 11/11] avoid String#-@ call on request parsing under Ruby 2.6
Date: Sat,  1 Dec 2018 13:31:25 +0000	[thread overview]
Message-ID: <20181201133125.5524-12-e@80x24.org> (raw)
In-Reply-To: <20181201133125.5524-1-e@80x24.org>

Ruby 2.6 will unconditionally dedupe all hash key strings
thanks to Anmol Chopra at https://bugs.ruby-lang.org/issues/15251
---
 ext/kcar/extconf.rb | 11 +++++++++++
 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)) {

      parent reply	other threads:[~2018-12-01 13:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-01 13:31 [PATCH v2] request parsing bits Eric Wong
2018-12-01 13:31 ` [PATCH 01/11] introduce new str_new_dd_freeze internal function Eric Wong
2018-12-01 13:31 ` [PATCH 02/11] begin implementing request parsing Eric Wong
2018-12-01 13:31 ` [PATCH 03/11] favor bitfields instead flags + macros Eric Wong
2018-12-01 13:31 ` [PATCH 04/11] implement request parsing with tests Eric Wong
2018-12-01 13:31 ` [PATCH 05/11] pkg.mk: enable warnings by default for tests Eric Wong
2018-12-01 13:31 ` [PATCH 06/11] filter_body: rename variables to be like memcpy(3) Eric Wong
2018-12-01 13:31 ` [PATCH 07/11] flesh out filter_body for request parsing Eric Wong
2018-12-01 13:31 ` [PATCH 08/11] do not assume SERVER_PORT Eric Wong
2018-12-01 13:31 ` [PATCH 09/11] do not set "HTTP/0.9" for pre-1.0 requests Eric Wong
2018-12-01 13:31 ` [PATCH 10/11] always set non-negative Content-Length for requests Eric Wong
2018-12-01 13:31 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/kcar/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181201133125.5524-12-e@80x24.org \
    --to=e@80x24.org \
    --cc=kcar-public@bogomips.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/kcar.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).