3 ms·
Does D fold strings with a common suffix? I.e. "bar" to a pointer into "foobar"
by JonChesterfield 4y ago
Does D fold strings with a common suffix? I.e. "bar" to a pointer into "foobar"
- WalterBright 4y agoI've thought about doing it a few times, but it didn't seem there was much oil in that well.
- JonChesterfield 4y agoI vaguely remember it as a pattern in a dwarf string table but can't remember if the memory saving was worth the compile time. Thanks
- nneonneo 4y agoFWIW, GCC does implement this optimization; see https://godbolt.org/z/o81xa94v7 https://godbolt.org/z/o81xa94v7 for an example. I've definitely run across real-world samples where it saved some bytes (at the expense of making reverse-engineering a bit more annoying!).
- astrange 4y agoIt only happens if you check "compile to binary" there, so I think the linker is actually doing it.