cpp-common/bt2: use bt2c::CStringView in parameters and return values throughout
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 16 Jan 2024 18:31:06 +0000 (13:31 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 29 Jan 2024 16:38:19 +0000 (11:38 -0500)
commit15030982ca99a8930d5c13b7fdff5dcba204a551
tree779faf4e7bf52844fbd0bb301b720f53d706e28f
parent26d1608e0ae2873fb8543bb8a2b6bf65f3567ecd
cpp-common/bt2: use bt2c::CStringView in parameters and return values throughout

From what I saw, at -O2 with gcc, passing and returning CStringViews
generates the same code as passing and returning `const char *`.  Change
the `cpp-common/bt2` code to take a return C strings using CStringViews
when possible, which is more convenient than `const char *`.

Since std::string is implicitly convertible to CStringView, there is
generaly no need to have separate overloads that take std::strings.

I left the `CommonStringField::append(const std::string &)` overload,
because this one has an advantage over the `CStringView` overload: it
uses the size of the `std::string`, which is cheaper than calling
`std::strlen`.

There are some cases where leaving the `const char *` overload is
necessary.  For instance, when there is also a `bool` overload.  In that
case, passing a `const char *` to the function would prefer the `bool`
overload over the `CStringView` overload, which is not what we want.

Change-Id: I4c995c995da3edd2f0e9f7034053d52cb1541bb0
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11690
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/cpp-common/bt2/clock-class.hpp
src/cpp-common/bt2/component-port.hpp
src/cpp-common/bt2/field-class.hpp
src/cpp-common/bt2/field.hpp
src/cpp-common/bt2/plugin-dev.hpp
src/cpp-common/bt2/raw-value-proxy.hpp
src/cpp-common/bt2/self-component-port.hpp
src/cpp-common/bt2/trace-ir.hpp
src/cpp-common/bt2/value.hpp
This page took 0.026199 seconds and 4 git commands to generate.