From: SASADA Koichi Date: 2013-10-04T09:28:54+09:00 Subject: [ruby-core:57648] Re: [ruby-trunk - Feature #8977] String#frozen that takes advantage of the deduping (2013/10/04 9:14), nobu (Nobuyoshi Nakada) wrote: > I don't think it needs a new method nor class. > > frozen_pool = Hash.new {|h, s| h[s.freeze] = s} > > 3.times { > p frozen_pool["foo"].object_id > } for `f' syntax, we prepare frozen string table. Let it name "FrozenTable". This proposal String#frozen can be defined by: class String def frozen FrozenTable[frozen] ||= self.freeze # rb_fstring(self) in C level end end The difference between hash table approach and rb_fstring() is GC. Frozen strings returned by Strign#frozen are collected if frozen strings are not marked. But hash table approach doesn't allow collecting. -- // SASADA Koichi at atdot dot net