Clarify detail about small-string optimization in FBString.
Summary: I was reading through about the various approaches to small-string optimization: https://shaharmike.com/cpp/std-string/. I noticed that Clang can store up to 22 bytes inline but FBString claims it can do 23, so I read through the code to figure out where the extra byte came from. Specifically, I wasn't sure how it could have space to store the size as well as ensure the buffer was null-terminated. After playing with the code for a bit (this was further complicated because running the code under ASAN changes the behavior, which I didn't realize before I started this exploration), I saw how we don't store the size, but `maxSmallSize - size`, so that null-termination works out even when `size==23`. This updates the docs to hopefully save someone else this same exploration. (Note: this ignores all push blocking failures!) Reviewed By: ot Differential Revision: D10258831 fbshipit-source-id: bfc0dd7ae55518af4173625bd719cfd4778180cc
Showing
Please register or sign in to comment