I'm not sure why `nameSuffix` is passed as a `const
bt2s::optional<std::string>&` currently. `bt2c::CStringView` seems like
a good fit for it. It avoids unnecessarily creating `std::string`s when
the caller passes a literal string.
Change-Id: I1412b77223fe01a70dda4c23558983f84dfb07d4
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12114
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
#include <babeltrace2/babeltrace.h>
#include "cpp-common/bt2/graph.hpp"
#include <babeltrace2/babeltrace.h>
#include "cpp-common/bt2/graph.hpp"
+#include "cpp-common/bt2c/c-string-view.hpp"
*/
template <typename FuncT>
CondTrigger *makeSimpleTrigger(FuncT&& func, const CondTrigger::Type type,
*/
template <typename FuncT>
CondTrigger *makeSimpleTrigger(FuncT&& func, const CondTrigger::Type type,
- const std::string& condId,
- const bt2s::optional<std::string>& nameSuffix = bt2s::nullopt)
+ const std::string& condId, const bt2c::CStringView nameSuffix = {})
{
return new SimpleCondTrigger {std::forward<FuncT>(func), type, condId, nameSuffix};
}
{
return new SimpleCondTrigger {std::forward<FuncT>(func), type, condId, nameSuffix};
}
*/
CondTrigger *makeRunInCompInitTrigger(OnCompInitFunc func, const CondTrigger::Type type,
const std::string& condId,
*/
CondTrigger *makeRunInCompInitTrigger(OnCompInitFunc func, const CondTrigger::Type type,
const std::string& condId,
- const bt2s::optional<std::string>& nameSuffix = bt2s::nullopt)
+ const bt2c::CStringView nameSuffix = {})
{
return new RunInCondTrigger<RunInDelegator> {RunInDelegator::makeOnCompInit(std::move(func)),
type, condId, nameSuffix};
{
return new RunInCondTrigger<RunInDelegator> {RunInDelegator::makeOnCompInit(std::move(func)),
type, condId, nameSuffix};
#include "utils.hpp"
CondTrigger::CondTrigger(const Type type, const std::string& condId,
#include "utils.hpp"
CondTrigger::CondTrigger(const Type type, const std::string& condId,
- const bt2s::optional<std::string>& nameSuffix) noexcept :
+ const bt2c::CStringView nameSuffix) noexcept :
_mType {type},
_mCondId {fmt::format("{}:{}", type == Type::PRE ? "pre" : "post", condId)},
_mType {type},
_mCondId {fmt::format("{}:{}", type == Type::PRE ? "pre" : "post", condId)},
- _mName {
- fmt::format("{}{}{}", condId, nameSuffix ? "-" : "", nameSuffix ? nameSuffix->data() : "")}
+ _mName {fmt::format("{}{}{}", condId, nameSuffix ? "-" : "", nameSuffix ? nameSuffix : "")}
{
}
SimpleCondTrigger::SimpleCondTrigger(std::function<void()> func, const Type type,
const std::string& condId,
{
}
SimpleCondTrigger::SimpleCondTrigger(std::function<void()> func, const Type type,
const std::string& condId,
- const bt2s::optional<std::string>& nameSuffix) :
+ const bt2c::CStringView nameSuffix) :
CondTrigger {type, condId, nameSuffix},
_mFunc {std::move(func)}
{
CondTrigger {type, condId, nameSuffix},
_mFunc {std::move(func)}
{
#include <babeltrace2/babeltrace.h>
#include <babeltrace2/babeltrace.h>
-#include "cpp-common/bt2s/optional.hpp"
+#include "cpp-common/bt2c/c-string-view.hpp"
#include "cpp-common/bt2s/span.hpp"
#include "../utils/run-in.hpp"
#include "cpp-common/bt2s/span.hpp"
#include "../utils/run-in.hpp"
* name of the created condition trigger with name().
*/
explicit CondTrigger(Type type, const std::string& condId,
* name of the created condition trigger with name().
*/
explicit CondTrigger(Type type, const std::string& condId,
- const bt2s::optional<std::string>& nameSuffix) noexcept;
+ const bt2c::CStringView nameSuffix) noexcept;
public:
virtual ~CondTrigger() = default;
public:
virtual ~CondTrigger() = default;
{
public:
explicit SimpleCondTrigger(std::function<void()> func, Type type, const std::string& condId,
{
public:
explicit SimpleCondTrigger(std::function<void()> func, Type type, const std::string& condId,
- const bt2s::optional<std::string>& nameSuffix = bt2s::nullopt);
+ const bt2c::CStringView nameSuffix = {});
void operator()() noexcept override
{
void operator()() noexcept override
{
{
public:
explicit RunInCondTrigger(RunInT runIn, const Type type, const std::string& condId,
{
public:
explicit RunInCondTrigger(RunInT runIn, const Type type, const std::string& condId,
- const bt2s::optional<std::string>& nameSuffix = bt2s::nullopt) :
+ const bt2c::CStringView nameSuffix = {}) :
CondTrigger {type, condId, nameSuffix},
_mRunIn {std::move(runIn)}
{
}
explicit RunInCondTrigger(const Type type, const std::string& condId,
CondTrigger {type, condId, nameSuffix},
_mRunIn {std::move(runIn)}
{
}
explicit RunInCondTrigger(const Type type, const std::string& condId,
- const bt2s::optional<std::string>& nameSuffix = bt2s::nullopt) :
+ const bt2c::CStringView nameSuffix = {}) :
RunInCondTrigger {RunInT {}, type, condId, nameSuffix}
{
}
RunInCondTrigger {RunInT {}, type, condId, nameSuffix}
{
}