ruby-changes:46095
From: nagachika <ko1@a...>
Date: Tue, 28 Mar 2017 01:02:56 +0900 (JST)
Subject: [ruby-changes:46095] nagachika:r58166 (ruby_2_3): merge revision(s) 57278, 57279: [Backport #12855]
nagachika 2017-03-28 01:02:50 +0900 (Tue, 28 Mar 2017) New Revision: 58166 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58166 Log: merge revision(s) 57278,57279: [Backport #12855] fix optimization for hash aset/aref with fstring Patch by Eric Wong [ruby-core:78797]. I don't like the idea of making insns.def any bigger to support a corner case, and "test_hash_aref_fstring_identity" shows how contrived this is. [ruby-core:78783] [Bug #12855] adjust indent [ci skip] Modified directories: branches/ruby_2_3/ Modified files: branches/ruby_2_3/hash.c branches/ruby_2_3/insns.def branches/ruby_2_3/internal.h branches/ruby_2_3/test/ruby/test_hash.rb branches/ruby_2_3/version.h Index: ruby_2_3/hash.c =================================================================== --- ruby_2_3/hash.c (revision 58165) +++ ruby_2_3/hash.c (revision 58166) @@ -2581,8 +2581,6 @@ rb_hash_flatten(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/ruby_2_3/hash.c#L2581 return ary; } -static VALUE rb_hash_compare_by_id_p(VALUE hash); - /* * call-seq: * hsh.compare_by_identity -> hsh @@ -2618,7 +2616,7 @@ rb_hash_compare_by_id(VALUE hash) https://github.com/ruby/ruby/blob/trunk/ruby_2_3/hash.c#L2616 * */ -static VALUE +VALUE rb_hash_compare_by_id_p(VALUE hash) { if (!RHASH(hash)->ntbl) Index: ruby_2_3/version.h =================================================================== --- ruby_2_3/version.h (revision 58165) +++ ruby_2_3/version.h (revision 58166) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1 #define RUBY_VERSION "2.3.3" #define RUBY_RELEASE_DATE "2017-03-28" -#define RUBY_PATCHLEVEL 275 +#define RUBY_PATCHLEVEL 276 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 3 Index: ruby_2_3/test/ruby/test_hash.rb =================================================================== --- ruby_2_3/test/ruby/test_hash.rb (revision 58165) +++ ruby_2_3/test/ruby/test_hash.rb (revision 58166) @@ -229,6 +229,19 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_hash.rb#L229 assert_same a.keys[0], b.keys[0] end + def test_hash_aset_fstring_identity + h = {}.compare_by_identity + h['abc'] = 1 + h['abc'] = 2 + assert_equal 2, h.size, '[ruby-core:78783] [Bug #12855]' + end + + def test_hash_aref_fstring_identity + h = {}.compare_by_identity + h['abc'] = 1 + assert_nil h['abc'], '[ruby-core:78783] [Bug #12855]' + end + def test_NEWHASH_fstring_key a = {"ABC" => :t} b = {"ABC" => :t} Index: ruby_2_3/internal.h =================================================================== --- ruby_2_3/internal.h (revision 58165) +++ ruby_2_3/internal.h (revision 58166) @@ -837,6 +837,7 @@ VALUE rb_hash_set_default_proc(VALUE has https://github.com/ruby/ruby/blob/trunk/ruby_2_3/internal.h#L837 long rb_objid_hash(st_index_t index); st_table *rb_init_identtable(void); st_table *rb_init_identtable_with_size(st_index_t size); +VALUE rb_hash_compare_by_id_p(VALUE hash); #define RHASH_TBL_RAW(h) rb_hash_tbl_raw(h) VALUE rb_hash_keys(VALUE hash); Index: ruby_2_3/insns.def =================================================================== --- ruby_2_3/insns.def (revision 58165) +++ ruby_2_3/insns.def (revision 58166) @@ -1904,7 +1904,9 @@ opt_aset_with https://github.com/ruby/ruby/blob/trunk/ruby_2_3/insns.def#L1904 (VALUE recv, VALUE val) (VALUE val) { - if (!SPECIAL_CONST_P(recv) && RBASIC_CLASS(recv) == rb_cHash && BASIC_OP_UNREDEFINED_P(BOP_ASET, HASH_REDEFINED_OP_FLAG)) { + if (!SPECIAL_CONST_P(recv) && RBASIC_CLASS(recv) == rb_cHash && + BASIC_OP_UNREDEFINED_P(BOP_ASET, HASH_REDEFINED_OP_FLAG) && + rb_hash_compare_by_id_p(recv) == Qfalse) { rb_hash_aset(recv, key, val); } else { @@ -1926,7 +1928,9 @@ opt_aref_with https://github.com/ruby/ruby/blob/trunk/ruby_2_3/insns.def#L1928 (VALUE recv) (VALUE val) { - if (!SPECIAL_CONST_P(recv) && RBASIC_CLASS(recv) == rb_cHash && BASIC_OP_UNREDEFINED_P(BOP_AREF, HASH_REDEFINED_OP_FLAG)) { + if (!SPECIAL_CONST_P(recv) && RBASIC_CLASS(recv) == rb_cHash && + BASIC_OP_UNREDEFINED_P(BOP_AREF, HASH_REDEFINED_OP_FLAG) && + rb_hash_compare_by_id_p(recv) == Qfalse) { val = rb_hash_aref(recv, key); } else { @@ -2075,8 +2079,7 @@ opt_succ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/insns.def#L2079 BASIC_OP_UNREDEFINED_P(BOP_SUCC, STRING_REDEFINED_OP_FLAG)) { val = rb_str_succ(recv); } - else - { + else { goto INSN_LABEL(normal_dispatch); } } Property changes on: ruby_2_3 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r57278-57279 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/