Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There 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.


I think Substring in Swift is something similar?


Yeah it’s pretty common optimization. Some languages do this with array slicing.


Why couldn't you do both?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: