News for hackers. Stuff that matters.
Re:Libc++'s Implementation of std::string by OskarS on Friday January 31, 2020 @08:14AM (#22201368)
Yeah, exactly :) when in SSO mode, it stores the size as a delta occupying a single byte, but when in heap-allocated mode, it stores the size as a an 8-byte size_t, and you require a branch to check which case is the right one. You can see the branch here in the source [0], and godbolt confirms that for std::string it's just a memory load [1]. A shame Folly isn't available on Compiler Explorer, would be interesting to compare.

[0]: https://github.com/facebook/folly/blob/master/folly/FBString...

[1]: https://godbolt.org/z/U-LvGm

There are no comments on this comment yet.