-
Notifications
You must be signed in to change notification settings - Fork 3
Description
The use of std::string as function parameters entails copies and dynamic memory allocation for every single call to a variable-specific routine, including the most repetitive and performance-sensitive, [GS]etValue[AtIndices]. None of the functions inherently need ownership of the passed string, nor do they specifically need functionality of the std::string type. The current std::string passed by value doesn't offer lifetime past the routine's return without internal copying/moving.
Modern C++ (from C++17) has a utility type string_view for exactly this situation, that supports arguments of types std::string const, char const*, and string literals that are typed as char const[], all without copying or allocation.
Ideally, I propose using std::string_view, and thus requiring associated C++ standard library support. This support appeared under -std=c++1z with GCC 7's libstdc++ and Clang 4's libc++
In the alternative where we really want to support platforms that are 3 full standards versions out-of-date, we could instead define a vendored implementation analog as bmi::string_view.
For lifetime management and ABI definition reasons, I'm not proposing here that string_view be used as part of arrays/vectors of strings in output arguments, return types, or the proposed supported_extensions parameter to Initialize(). I think those can and probably should be done too, but they require a bit more consideration.