Why is initializing a string to “” more efficient than the default constructor?
This is an intentional decision in libc++’s implementation of std::string. First of all, std::string has so-called Small String Optimization (SSO), which means that for very short (or empty) strings, it will store their contents directly inside of the container, rather than allocating dynamic memory. That’s why we don’t see any allocations in either case. In … Read more