]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
exporter: use string_view for file and function name
authorKefu Chai <tchaikov@gmail.com>
Tue, 13 Feb 2024 06:41:00 +0000 (14:41 +0800)
committerKefu Chai <tchaikov@gmail.com>
Tue, 13 Feb 2024 06:44:08 +0000 (14:44 +0800)
according to
https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html,
both __FILE__ and __FUNCTION__ expand to C string constants. so no
need to store them as a std::string. let's use std::string_view instead.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
src/exporter/util.cc
src/exporter/util.h

index 6def113a5d4d65d019746842bd5bddc7deffba60..d6b4ba01ca766ea1f5220c4ff0dd856bb6292b16 100644 (file)
 #define dout_context g_ceph_context
 #define dout_subsys ceph_subsys_ceph_exporter
 
-BlockTimer::BlockTimer(std::string file, std::string function)
-       : file(file), function(function), stopped(false) {
+BlockTimer::BlockTimer(std::string_view file, std::string_view function)
+       : file(file),
+    function(function),
+    stopped(false) {
        t1 = clock_t::now();
 }
 BlockTimer::~BlockTimer() {
index 2f4eaebb6152d3e02a227d4ed7b9004be4f2dc9b..9adc128d2b4a8ad6f75d81e64cae3a5c05bb997d 100644 (file)
@@ -1,15 +1,16 @@
 #include "common/hostname.h"
 #include <chrono>
-#include <string>
+#include <string_view>
 
 class BlockTimer {
  public:
-       BlockTimer(std::string file, std::string function);
+       BlockTimer(std::string_view file, std::string_view function);
        ~BlockTimer();
        void stop();
        double get_ms() const;
  private:
-       std::string file, function;
+       const std::string_view file;
+       const std::string_view function;
        bool stopped;
        using clock_t = std::chrono::steady_clock;
        clock_t::time_point t1;