3 ms·
How does that work? “Foo” isn’t a prefix of “Foobar” because it’s actually “Foo\0” and “Foobar\0”.
by User23 4y ago
How does that work? “Foo” isn’t a prefix of “Foobar” because it’s actually “Foo\0” and “Foobar\0”.
- JonChesterfield 4y agoIf the strings have a 0 after them suffixes are more likely to fold than prefixes. bar\0.
- nneonneo 4y ago`"dear friend"` is in fact a prefix of `"dear friend\0f"` - note the embedded null byte. However, I'm guessing GCC doesn't implement this optimization because it's uncommon for a string constant to contain an embedded null. GCC does implement suffix deduplication, though: `"foobar"` and `"bar"` share the same storage. For example, in https://godbolt.org/z/o81xa94v7 https://godbolt.org/z/o81xa94v7, `foobar` is at 0x402004 and `bar` is at 0x402007.
- User23 4y agoYeah that’s a neat trick. SBCL does that with compiled code. It will use different entry points into a function based on the type checker. So checked and unchecked calls share a suffix of machine code.