From 4ad4365795e89089c88b28c483bb19fe77091632 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 20 Mar 2024 15:58:44 -0400 Subject: [PATCH] tests/lib/conds: change `nameSuffix` type to `bt2c::CStringView` I'm not sure why `nameSuffix` is passed as a `const bt2s::optional&` 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 Reviewed-on: https://review.lttng.org/c/babeltrace/+/12114 Reviewed-by: Philippe Proulx Tested-by: jenkins --- tests/lib/conds/conds-triggers.cpp | 6 +++--- tests/lib/conds/utils.cpp | 7 +++---- tests/lib/conds/utils.hpp | 10 +++++----- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/tests/lib/conds/conds-triggers.cpp b/tests/lib/conds/conds-triggers.cpp index c3ce48fa..1a463511 100644 --- a/tests/lib/conds/conds-triggers.cpp +++ b/tests/lib/conds/conds-triggers.cpp @@ -9,6 +9,7 @@ #include #include "cpp-common/bt2/graph.hpp" +#include "cpp-common/bt2c/c-string-view.hpp" #include "utils.hpp" @@ -19,8 +20,7 @@ namespace { */ template CondTrigger *makeSimpleTrigger(FuncT&& func, const CondTrigger::Type type, - const std::string& condId, - const bt2s::optional& nameSuffix = bt2s::nullopt) + const std::string& condId, const bt2c::CStringView nameSuffix = {}) { return new SimpleCondTrigger {std::forward(func), type, condId, nameSuffix}; } @@ -62,7 +62,7 @@ private: */ CondTrigger *makeRunInCompInitTrigger(OnCompInitFunc func, const CondTrigger::Type type, const std::string& condId, - const bt2s::optional& nameSuffix = bt2s::nullopt) + const bt2c::CStringView nameSuffix = {}) { return new RunInCondTrigger {RunInDelegator::makeOnCompInit(std::move(func)), type, condId, nameSuffix}; diff --git a/tests/lib/conds/utils.cpp b/tests/lib/conds/utils.cpp index 9bf5450f..d393c618 100644 --- a/tests/lib/conds/utils.cpp +++ b/tests/lib/conds/utils.cpp @@ -17,17 +17,16 @@ #include "utils.hpp" CondTrigger::CondTrigger(const Type type, const std::string& condId, - const bt2s::optional& nameSuffix) noexcept : + const bt2c::CStringView nameSuffix) noexcept : _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 func, const Type type, const std::string& condId, - const bt2s::optional& nameSuffix) : + const bt2c::CStringView nameSuffix) : CondTrigger {type, condId, nameSuffix}, _mFunc {std::move(func)} { diff --git a/tests/lib/conds/utils.hpp b/tests/lib/conds/utils.hpp index c1288c4f..d742d908 100644 --- a/tests/lib/conds/utils.hpp +++ b/tests/lib/conds/utils.hpp @@ -13,7 +13,7 @@ #include -#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" @@ -48,7 +48,7 @@ protected: * name of the created condition trigger with name(). */ explicit CondTrigger(Type type, const std::string& condId, - const bt2s::optional& nameSuffix) noexcept; + const bt2c::CStringView nameSuffix) noexcept; public: virtual ~CondTrigger() = default; @@ -88,7 +88,7 @@ class SimpleCondTrigger : public CondTrigger { public: explicit SimpleCondTrigger(std::function func, Type type, const std::string& condId, - const bt2s::optional& nameSuffix = bt2s::nullopt); + const bt2c::CStringView nameSuffix = {}); void operator()() noexcept override { @@ -111,14 +111,14 @@ class RunInCondTrigger : public CondTrigger { public: explicit RunInCondTrigger(RunInT runIn, const Type type, const std::string& condId, - const bt2s::optional& nameSuffix = bt2s::nullopt) : + const bt2c::CStringView nameSuffix = {}) : CondTrigger {type, condId, nameSuffix}, _mRunIn {std::move(runIn)} { } explicit RunInCondTrigger(const Type type, const std::string& condId, - const bt2s::optional& nameSuffix = bt2s::nullopt) : + const bt2c::CStringView nameSuffix = {}) : RunInCondTrigger {RunInT {}, type, condId, nameSuffix} { } -- 2.34.1