From: Robert Klemme Date: 2004-12-28T23:01:48+09:00 Subject: Re: help on making ruby code faster "David Garamond" schrieb im Newsbeitrag news:41D16479.8000408@zara.6.isreserved.com... > Robert Klemme wrote: > >>Can't Ruby currently optimize those? I frankly don't want to have to do > >>those kinds of optimization myself :-( > > > > It does (by sharing the internal string buffer) but it still has to create > > new String instances on each run: > > > >>>5.times { p 's'.id } > > > > 134947060 > > 134946988 > > 134696172 > > 134690592 > > 134690544 > > => 5 > > > > If it would not do this, code like this would yield unexpected results: > > > >>>5.times { p 'abc'[1] += 1 } > > I see. Suddenly I want immutable strings like in Python. At least there is freeze. In such a situation I do typically this: class SillyExample FOO = "my prefix".freeze def prefix(s) FOO + s end end > Hm, it seems optimizing Ruby programs is pretty tedious? One has to > scorch through every string literal... No, only those that are performance critical. :-) Regards robert