3 ms·
(Frozen string literals allows strings to be in memory only once and not having to reallocate each time, so a pretty big memory and cpu optimization) Isn't thi
by uiri 10y ago
(Frozen string literals allows strings to be in memory only once and not having to reallocate each time, so a pretty big memory and cpu optimization)
Isn't this the purpose of symbols in the language? This seems like a pretty basic optimization, surely there were good reasons not to introduce it in earlier versions.
- dorianm 10y agoe.g. 1000.times { "hello" } creates strings 1000 times but: 1000.times { "hello".freeze } only one time. The thing about frozen strings is they can't be changed "inline": e.g. : "Hello".freeze << " world" doesn't work but "Hello".freeze + " world" does because it creates a new string. (It's funny because << is often recommended as an optimization)