3 ms·
So essentially string interning for Ruby?
by PricelessValue 9y ago
So essentially string interning for Ruby?
- hyperpape 9y agoThere are significant differences. Depending on the case, it can be more or less effective. 1) If you intern all strings, then you're guaranteed to have one copy of "Hello World", which this doesn't (you could concatenate "Hello" and "World" twice). 2) String interning doesn't let similar strings share the same array. The Ruby trick lets you have "Hello World" "World" "orld" "rld" "ld" "d" all share the same underlying array, whereas string interning gives you a separate array for each.
- rimliu 9y agoI think Substring in Swift is something similar?
- _sdegutis 9y agoYeah it’s pretty common optimization. Some languages do this with array slicing.
- smitherfield 9y agoWhy couldn't you do both?