From: Rob Biedenharn Date: 2009-04-02T13:17:01+09:00 Subject: Re: Symbols garbage collector in Ruby1.9, fixed? On Apr 1, 2009, at 8:03 PM, Iñaki Baz Castillo wrote: > El Jueves 02 Abril 2009, Tony Arcieri escribió: > >> Use symbols... FOR SPEED! Unfortunately that speed comes at a >> price... you >> really want to globally internalize arbitrary input? Symbols are >> effectively a freeform enumeration... the reason you're running into >> problems is because you're trying to enumerate arbitrary inputs. > > Yes. It's a parser so custom headers could arrive. I want to store > them in a > hash like: > > headers = { :from => "alice@qweeq", ":to => "bob@qweqwe } > > So after parsing the message I create these entries. The problem is > that any > custom header would create a Symbol. > > >> Is this really an important bottleneck in your application? > > I think it's important since after parsing hte main task of the > server will be > accessing some headers to read their content. But since it's just in > a very > early stage I cannot sure it. > > Thanks. > -- > Iñaki Baz Castillo Just key the hash with Strings: headers = { 'from' => "alice@qweeq", 'to' => "bob@qweeq" } If you really need to use symbols, perhaps add methods to a subclass of Hash like the HashWithIndifferentAccess from Rails which mostly eliminates the need to care whether you actually stored against a Symbol or a String key. There's also nothing stopping you from having both kinds of keys at once: headers = { :from => "alice@qweeq", :to => "bob@qweeq", 'snack' => "raisins" } but then you might have to "worry" about having both :to and 'to' as keys. Symbols are only faster because they are immutable and don't get garbage collected. But I'd go with Tony and just use String all the time. -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com