ruby-changes:48222
From: glass <ko1@a...>
Date: Sun, 22 Oct 2017 09:57:52 +0900 (JST)
Subject: [ruby-changes:48222] glass:r60337 (trunk): hash.c: optimize Hash#compare_by_identity
glass 2017-10-22 09:57:46 +0900 (Sun, 22 Oct 2017) New Revision: 60337 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60337 Log: hash.c: optimize Hash#compare_by_identity hash.c (rb_hash_compare_by_id): avoid unnecessary allocation of st_table. formerly, st_table created in rb_hash_modify() was not used and replaced immediately. Modified files: trunk/hash.c Index: hash.c =================================================================== --- hash.c (revision 60336) +++ hash.c (revision 60337) @@ -2899,10 +2899,16 @@ rb_hash_compact_bang(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L2899 static VALUE rb_hash_compare_by_id(VALUE hash) { + st_table *identtable; if (rb_hash_compare_by_id_p(hash)) return hash; - rb_hash_modify(hash); - RHASH(hash)->ntbl->type = &identhash; - rb_hash_rehash(hash); + rb_hash_modify_check(hash); + + identtable = rb_init_identtable_with_size(RHASH_SIZE(hash)); + rb_hash_foreach(hash, rb_hash_rehash_i, (VALUE)identtable); + if (RHASH(hash)->ntbl) + st_free_table(RHASH(hash)->ntbl); + RHASH(hash)->ntbl = identtable; + return hash; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/