diff options
author | Eric Wong <e@80x24.org> | 2018-12-06 23:26:24 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2018-12-12 23:49:38 +0000 |
commit | 16f7018af1f278a9f0cc368e224258860ea4cb8c (patch) | |
tree | 3b4a7149d3f02220023e92a653ce53bdd2c0442b /test/unit/test_http_parser.rb | |
parent | 981f561a726bb4307d01e4a09a308edba8d69fe3 (diff) | |
download | unicorn-16f7018af1f278a9f0cc368e224258860ea4cb8c.tar.gz |
String#-@ deduplicates strings starting with Ruby 2.5.0 Hash#[]= deduplicates strings starting in Ruby 2.6.0-rc1 This allows us to save a small amount of memory by sharing objects with other parts of the stack (e.g. Rack).
Diffstat (limited to 'test/unit/test_http_parser.rb')
-rw-r--r-- | test/unit/test_http_parser.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/unit/test_http_parser.rb b/test/unit/test_http_parser.rb index 31e6f71..697af44 100644 --- a/test/unit/test_http_parser.rb +++ b/test/unit/test_http_parser.rb @@ -865,4 +865,20 @@ class HttpParserTest < Test::Unit::TestCase rescue LoadError # not all Ruby implementations have objspace end + + def test_dedupe + parser = HttpParser.new + # n.b. String#freeze optimization doesn't work under modern test-unit + exp = -'HTTP_HOST' + get = "GET / HTTP/1.1\r\nHost: example.com\r\nHavpbea-fhpxf: true\r\n\r\n" + assert parser.add_parse(get) + key = parser.env.keys.detect { |k| k == exp } + assert_same exp, key + + if RUBY_VERSION.to_r >= 2.6 # 2.6.0-rc1+ + exp = -'HTTP_HAVPBEA_FHPXF' + key = parser.env.keys.detect { |k| k == exp } + assert_same exp, key + end + end if RUBY_VERSION.to_r >= 2.5 && RUBY_ENGINE == 'ruby' end |