]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
log: remove SubsystemMap::m_max_name_len.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Tue, 13 Feb 2018 14:26:24 +0000 (15:26 +0100)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Tue, 27 Feb 2018 10:38:48 +0000 (11:38 +0100)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/common/subsys_types.h
src/log/SubsystemMap.h

index a87ea1a0f3a73ae3499da98befafdb456cd0556b..385fbc4209fc346b7406e1d317dc2d78f9b8b7e6 100644 (file)
@@ -15,6 +15,7 @@
 #ifndef CEPH_SUBSYS_TYPES_H
 #define CEPH_SUBSYS_TYPES_H
 
+#include <algorithm>
 #include <array>
 
 enum ceph_subsys_id_t {
@@ -52,5 +53,28 @@ ceph_subsys_get_as_array() {
 #undef DEFAULT_SUBSYS
 }
 
+// Compile time-capable version of std::strlen. Resorting to own
+// implementation only because C++17 doesn't mandate constexpr
+// on the standard one.
+constexpr static std::size_t strlen_ct(const char* const s) {
+  std::size_t l = 0;
+  while (s[l] != '\0') {
+    ++l;
+  }
+  return l;
+}
+
+constexpr static std::size_t ceph_subsys_max_name_length() {
+  return std::max({
+#define SUBSYS(name, log, gather) \
+  strlen_ct(#name),
+#define DEFAULT_SUBSYS(log, gather) \
+  strlen_ct("none"),
+#include "common/subsys.h"
+#undef SUBSYS
+#undef DEFAULT_SUBSYS
+  });
+}
+
 #endif // CEPH_SUBSYS_TYPES_H
 
index 5266df7bc310dad93feff63b78f563dbf46c9c94..508263d1ba6e4ec723faefb4a8d768cd4429c360 100644 (file)
@@ -26,13 +26,10 @@ class SubsystemMap {
   // lines. Access can be slow.
   std::vector<ceph_subsys_item_t> m_subsys;
 
-  // TODO(rzarzynski): knock this out with constexpr.
-  unsigned m_max_name_len = 0;
-
   friend class Log;
 
 public:
-  SubsystemMap() : m_max_name_len(0) {
+  SubsystemMap() {
     constexpr auto s = ceph_subsys_get_as_array();
     m_subsys.reserve(s.size());
 
@@ -40,18 +37,15 @@ public:
     for (const ceph_subsys_item_t& item : s) {
       m_subsys.emplace_back(item);
       m_gather_levels[i++] = std::max(item.log_level, item.gather_level);
-
-      m_max_name_len = std::max(m_max_name_len,
-        static_cast<unsigned>(strlen(item.name)));
     }
   }
 
-  constexpr static size_t get_num() {
+  constexpr static std::size_t get_num() {
     return ceph_subsys_get_num();
   }
 
-  int get_max_subsys_len() const {
-    return m_max_name_len;
+  constexpr static std::size_t get_max_subsys_len() {
+    return ceph_subsys_max_name_length();
   }
 
   int get_log_level(unsigned subsys) const {