Das Problem mit German Strings

22 points by asubiotto


krig

Coming up with string representation optimizations is a lot of fun. When I worked in games, we had our own string class with a short-string optimization. Back then, the std::string implementation lacked this.

One thought I had when reading this and the original article was that it seems slightly wasteful to store a 32 bit length even for short strings: It shouldn’t be too tricky to use 15 bytes of the buffer for the short string optimization instead of just 12, and just reserve one bit to indicate if the string is short or not. Maybe that’s overkill.

Storing a prefix in the ptr case is clever, though.. especially when strings are immutable so storing a cap doesn’t make sense.

scruss

Someone’s just re-implemented Pascal strings, haven’t they?

(Yes, I know Pascal only had a single byte for length, but the concept’s the same until the string gets big)