ruby-changes:22319
From: nobu <ko1@a...>
Date: Tue, 24 Jan 2012 13:29:18 +0900 (JST)
Subject: [ruby-changes:22319] nobu:r34368 (trunk): * object.c (rb_Hash): trivial optimization.
nobu 2012-01-24 13:29:07 +0900 (Tue, 24 Jan 2012) New Revision: 34368 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34368 Log: * object.c (rb_Hash): trivial optimization. * test/ruby/test_object.rb (TestObject#test_convert_hash): fix arguments order. Modified files: trunk/object.c trunk/test/ruby/test_object.rb Index: object.c =================================================================== --- object.c (revision 34367) +++ object.c (revision 34368) @@ -2600,7 +2600,7 @@ if (NIL_P(val)) return rb_hash_new(); VALUE tmp = rb_check_hash_type(val); if (NIL_P(tmp)) { - if (TYPE(val) == T_ARRAY && RARRAY_LEN(val) == 0) + if (RB_TYPE_P(val, T_ARRAY) && RARRAY_LEN(val) == 0) return rb_hash_new(); rb_raise(rb_eTypeError, "can't convert %s into Hash", rb_obj_classname(val)); } Index: test/ruby/test_object.rb =================================================================== --- test/ruby/test_object.rb (revision 34367) +++ test/ruby/test_object.rb (revision 34368) @@ -198,14 +198,14 @@ end def test_convert_hash - assert_equal(Hash(nil), {}) - assert_equal(Hash([]), {}) - assert_equal(Hash(key: :value), {key: :value}) + assert_equal({}, Hash(nil)) + assert_equal({}, Hash([])) + assert_equal({key: :value}, Hash(key: :value)) assert_raise(TypeError) { Hash([1,2]) } assert_raise(TypeError) { Hash(Object.new) } o = Object.new def o.to_hash; {a: 1, b: 2}; end - assert_equal(Hash(o), {a: 1, b: 2}) + assert_equal({a: 1, b: 2}, Hash(o)) def o.to_hash; 9; end assert_raise(TypeError) { Hash(o) } end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/