tests/lib/conds: change `nameSuffix` type to `bt2c::CStringView`
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 20 Mar 2024 19:58:44 +0000 (15:58 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 26 Mar 2024 18:56:36 +0000 (14:56 -0400)
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>
tests/lib/conds/conds-triggers.cpp
tests/lib/conds/utils.cpp
tests/lib/conds/utils.hpp

index c3ce48fa42b4aa8c8997283dd4a03f9b0fc3425e..1a463511b0fcff540748ff98ea82882ee41cdb1b 100644 (file)
@@ -9,6 +9,7 @@
 #include <babeltrace2/babeltrace.h>
 
 #include "cpp-common/bt2/graph.hpp"
+#include "cpp-common/bt2c/c-string-view.hpp"
 
 #include "utils.hpp"
 
@@ -19,8 +20,7 @@ namespace {
  */
 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};
 }
@@ -62,7 +62,7 @@ private:
  */
 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};
index 9bf5450fe5bf56ab461c54e80ccab1439edc5b47..d393c618a0689bf8fd98efa6a3359f00a7cf41e0 100644 (file)
 #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)},
-    _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,
-                                     const bt2s::optional<std::string>& nameSuffix) :
+                                     const bt2c::CStringView nameSuffix) :
     CondTrigger {type, condId, nameSuffix},
     _mFunc {std::move(func)}
 {
index c1288c4f52a51f0bedb36c733502210966f8249e..d742d9088f317d9a42405752cc17a2244e185462 100644 (file)
@@ -13,7 +13,7 @@
 
 #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"
@@ -48,7 +48,7 @@ protected:
      * 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;
@@ -88,7 +88,7 @@ class SimpleCondTrigger : public CondTrigger
 {
 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
     {
@@ -111,14 +111,14 @@ class RunInCondTrigger : public CondTrigger
 {
 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,
-                              const bt2s::optional<std::string>& nameSuffix = bt2s::nullopt) :
+                              const bt2c::CStringView nameSuffix = {}) :
         RunInCondTrigger {RunInT {}, type, condId, nameSuffix}
     {
     }
This page took 0.026609 seconds and 4 git commands to generate.