summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-27 16:02:50 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-27 16:02:50 +0000
commit0d399220b02adb104b7cbd2fd4cb1055350a560c (patch)
tree46df61c345082caa6753e9924cca0a92fd325a37
parent7cbc39be6973b3a6ade414f42cdcf156efb3dee6 (diff)
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@58166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--hash.c4
-rw-r--r--insns.def11
-rw-r--r--internal.h1
-rw-r--r--test/ruby/test_hash.rb13
-rw-r--r--version.h2
5 files changed, 23 insertions, 8 deletions
diff --git a/hash.c b/hash.c
index 345d8f7971..58a3d04023 100644
--- a/hash.c
+++ b/hash.c
@@ -2581,8 +2581,6 @@ rb_hash_flatten(int argc, VALUE *argv, VALUE hash)
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)
*
*/
-static VALUE
+VALUE
rb_hash_compare_by_id_p(VALUE hash)
{
if (!RHASH(hash)->ntbl)
diff --git a/insns.def b/insns.def
index 2deb199d4c..b6a87734c0 100644
--- a/insns.def
+++ b/insns.def
@@ -1904,7 +1904,9 @@ opt_aset_with
(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
(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
BASIC_OP_UNREDEFINED_P(BOP_SUCC, STRING_REDEFINED_OP_FLAG)) {
val = rb_str_succ(recv);
}
- else
- {
+ else {
goto INSN_LABEL(normal_dispatch);
}
}
diff --git a/internal.h b/internal.h
index bf238059b9..6eb01d8b74 100644
--- a/internal.h
+++ b/internal.h
@@ -837,6 +837,7 @@ VALUE rb_hash_set_default_proc(VALUE hash, VALUE proc);
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);
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb
index 83c52a0c73..f56b6a9e1f 100644
--- a/test/ruby/test_hash.rb
+++ b/test/ruby/test_hash.rb
@@ -229,6 +229,19 @@ class TestHash < Test::Unit::TestCase
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}
diff --git a/version.h b/version.h
index b677ea3e30..9ab062b36a 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#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