]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
include/types: un-inline methods to reduce compile times
authorMax Kellermann <max.kellermann@ionos.com>
Tue, 29 Oct 2024 08:11:33 +0000 (09:11 +0100)
committerMax Kellermann <max.kellermann@ionos.com>
Tue, 5 Aug 2025 08:28:02 +0000 (10:28 +0200)
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
src/CMakeLists.txt
src/crimson/CMakeLists.txt
src/include/types.cc [new file with mode: 0644]
src/include/types.h

index 88964a1f685e26c6b0886619b3e0684c494eac3f..1e21cb21f3609d6f671ff2f32e92ad4acc4a946d 100644 (file)
@@ -502,6 +502,7 @@ set(libcommon_files
   xxHash/xxhash.c
   include/invoke_date.cc
   include/object.cc
+  include/types.cc
   include/utime.cc
   include/uuid.cc
   common/error_code.cc
index e53846843ecc0361d493fd70d5ba5104765f4368..8fb417fe35910c0add0c387ae0cd0461e2092aa5 100644 (file)
@@ -99,6 +99,7 @@ add_library(crimson-common STATIC
   ${PROJECT_SOURCE_DIR}/src/global/global_context.cc
   ${PROJECT_SOURCE_DIR}/src/global/pidfile.cc
   ${PROJECT_SOURCE_DIR}/src/include/object.cc
+  ${PROJECT_SOURCE_DIR}/src/include/types.cc
   ${PROJECT_SOURCE_DIR}/src/include/utime.cc
   ${PROJECT_SOURCE_DIR}/src/include/uuid.cc
   ${PROJECT_SOURCE_DIR}/src/librbd/Features.cc
diff --git a/src/include/types.cc b/src/include/types.cc
new file mode 100644 (file)
index 0000000..bbafa04
--- /dev/null
@@ -0,0 +1,129 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#include "types.h"
+
+#include <iomanip>
+
+namespace {
+inline std::ostream& format_u(std::ostream& out, const uint64_t v, const uint64_t n,
+      const int index, const uint64_t mult, const char* u)
+  {
+    char buffer[32];
+
+    if (index == 0) {
+      (void) snprintf(buffer, sizeof(buffer), "%" PRId64 "%s", n, u);
+    } else if ((v % mult) == 0) {
+      // If this is an even multiple of the base, always display
+      // without any decimal fraction.
+      (void) snprintf(buffer, sizeof(buffer), "%" PRId64 "%s", n, u);
+    } else {
+      // We want to choose a precision that reflects the best choice
+      // for fitting in 5 characters.  This can get rather tricky when
+      // we have numbers that are very close to an order of magnitude.
+      // For example, when displaying 10239 (which is really 9.999K),
+      // we want only a single place of precision for 10.0K.  We could
+      // develop some complex heuristics for this, but it's much
+      // easier just to try each combination in turn.
+      int i;
+      for (i = 2; i >= 0; i--) {
+        if (snprintf(buffer, sizeof(buffer), "%.*f%s", i,
+          static_cast<double>(v) / mult, u) <= 7)
+          break;
+      }
+    }
+
+    return out << buffer;
+  }
+}
+
+void client_t::dump(ceph::Formatter *f) const {
+  f->dump_int("id", v);
+}
+
+void client_t::generate_test_instances(std::list<client_t*>& ls) {
+  ls.push_back(new client_t);
+  ls.push_back(new client_t(1));
+  ls.push_back(new client_t(123));
+}
+
+std::ostream& operator<<(std::ostream& out, const client_t& c) {
+  return out << c.v;
+}
+
+std::ostream& operator<<(std::ostream& out, const si_u_t& b)
+{
+  uint64_t n = b.v;
+  int index = 0;
+  uint64_t mult = 1;
+  const char* u[] = {"", "k", "M", "G", "T", "P", "E"};
+
+  while (n >= 1000 && index < 7) {
+    n /= 1000;
+    index++;
+    mult *= 1000;
+  }
+
+  return format_u(out, b.v, n, index, mult, u[index]);
+}
+
+std::ostream& operator<<(std::ostream& out, const byte_u_t& b)
+{
+  uint64_t n = b.v;
+  int index = 0;
+  const char* u[] = {" B", " KiB", " MiB", " GiB", " TiB", " PiB", " EiB"};
+
+  while (n >= 1024 && index < 7) {
+    n /= 1024;
+    index++;
+  }
+
+  return format_u(out, b.v, n, index, 1ULL << (10 * index), u[index]);
+}
+
+std::ostream& operator<<(std::ostream& out, const ceph_mon_subscribe_item& i)
+{
+  return out << (long)i.start
+            << ((i.flags & CEPH_SUBSCRIBE_ONETIME) ? "" : "+");
+}
+
+std::ostream& operator<<(std::ostream& out, const weightf_t& w)
+{
+  if (w.v < -0.01F) {
+    return out << "-";
+  } else if (w.v < 0.000001F) {
+    return out << "0";
+  } else {
+    std::streamsize p = out.precision();
+    return out << std::fixed << std::setprecision(5) << w.v << std::setprecision(p);
+ }
+}
+
+void shard_id_t::dump(ceph::Formatter *f) const {
+  f->dump_int("id", id);
+}
+
+void shard_id_t::generate_test_instances(std::list<shard_id_t*>& ls) {
+  ls.push_back(new shard_id_t(1));
+  ls.push_back(new shard_id_t(2));
+}
+
+void errorcode32_t::dump(ceph::Formatter *f) const {
+  f->dump_int("code", code);
+}
+
+void errorcode32_t::generate_test_instances(std::list<errorcode32_t*>& ls) {
+  ls.push_back(new errorcode32_t(1));
+  ls.push_back(new errorcode32_t(2));
+}
index 90d068606d4de46563d2c1fb103a5ce62ee026d3..f3404495ed53759d3fd29cf9b9b352ba53844c42 100644 (file)
@@ -411,14 +411,8 @@ struct client_t {
     using ceph::decode;
     decode(v, bl);
   }
-  void dump(ceph::Formatter *f) const {
-    f->dump_int("id", v);
-  }
-  static void generate_test_instances(std::list<client_t*>& ls) {
-    ls.push_back(new client_t);
-    ls.push_back(new client_t(1));
-    ls.push_back(new client_t(123));
-  }
+  void dump(ceph::Formatter *f) const;
+  static void generate_test_instances(std::list<client_t*>& ls);
 };
 WRITE_CLASS_ENCODER(client_t)
 
@@ -432,46 +426,10 @@ static inline bool operator>=(const client_t& l, const client_t& r) { return l.v
 static inline bool operator>=(const client_t& l, int64_t o) { return l.v >= o; }
 static inline bool operator<(const client_t& l, int64_t o) { return l.v < o; }
 
-inline std::ostream& operator<<(std::ostream& out, const client_t& c) {
-  return out << c.v;
-}
-
-
+std::ostream& operator<<(std::ostream& out, const client_t& c);
 
 // --
 
-namespace {
-inline std::ostream& format_u(std::ostream& out, const uint64_t v, const uint64_t n,
-      const int index, const uint64_t mult, const char* u)
-  {
-    char buffer[32];
-
-    if (index == 0) {
-      (void) snprintf(buffer, sizeof(buffer), "%" PRId64 "%s", n, u);
-    } else if ((v % mult) == 0) {
-      // If this is an even multiple of the base, always display
-      // without any decimal fraction.
-      (void) snprintf(buffer, sizeof(buffer), "%" PRId64 "%s", n, u);
-    } else {
-      // We want to choose a precision that reflects the best choice
-      // for fitting in 5 characters.  This can get rather tricky when
-      // we have numbers that are very close to an order of magnitude.
-      // For example, when displaying 10239 (which is really 9.999K),
-      // we want only a single place of precision for 10.0K.  We could
-      // develop some complex heuristics for this, but it's much
-      // easier just to try each combination in turn.
-      int i;
-      for (i = 2; i >= 0; i--) {
-        if (snprintf(buffer, sizeof(buffer), "%.*f%s", i,
-          static_cast<double>(v) / mult, u) <= 7)
-          break;
-      }
-    }
-
-    return out << buffer;
-  }
-}
-
 /*
  * Use this struct to pretty print values that should be formatted with a
  * decimal unit prefix (the classic SI units). No actual unit will be added.
@@ -481,21 +439,7 @@ struct si_u_t {
   explicit si_u_t(uint64_t _v) : v(_v) {};
 };
 
-inline std::ostream& operator<<(std::ostream& out, const si_u_t& b)
-{
-  uint64_t n = b.v;
-  int index = 0;
-  uint64_t mult = 1;
-  const char* u[] = {"", "k", "M", "G", "T", "P", "E"};
-
-  while (n >= 1000 && index < 7) {
-    n /= 1000;
-    index++;
-    mult *= 1000;
-  }
-
-  return format_u(out, b.v, n, index, mult, u[index]);
-}
+std::ostream& operator<<(std::ostream& out, const si_u_t& b);
 
 /*
  * Use this struct to pretty print values that should be formatted with a
@@ -513,25 +457,8 @@ struct byte_u_t {
 template <> struct fmt::formatter<byte_u_t> : fmt::ostream_formatter {};
 #endif
 
-inline std::ostream& operator<<(std::ostream& out, const byte_u_t& b)
-{
-  uint64_t n = b.v;
-  int index = 0;
-  const char* u[] = {" B", " KiB", " MiB", " GiB", " TiB", " PiB", " EiB"};
-
-  while (n >= 1024 && index < 7) {
-    n /= 1024;
-    index++;
-  }
-
-  return format_u(out, b.v, n, index, 1ULL << (10 * index), u[index]);
-}
-
-inline std::ostream& operator<<(std::ostream& out, const ceph_mon_subscribe_item& i)
-{
-  return out << (long)i.start
-            << ((i.flags & CEPH_SUBSCRIBE_ONETIME) ? "" : "+");
-}
+std::ostream& operator<<(std::ostream& out, const byte_u_t& b);
+std::ostream& operator<<(std::ostream& out, const ceph_mon_subscribe_item& i);
 
 struct weightf_t {
   float v;
@@ -539,17 +466,7 @@ struct weightf_t {
   weightf_t(float _v) : v(_v) {}
 };
 
-inline std::ostream& operator<<(std::ostream& out, const weightf_t& w)
-{
-  if (w.v < -0.01F) {
-    return out << "-";
-  } else if (w.v < 0.000001F) {
-    return out << "0";
-  } else {
-    std::streamsize p = out.precision();
-    return out << std::fixed << std::setprecision(5) << w.v << std::setprecision(p);
-  }
-}
+std::ostream& operator<<(std::ostream& out, const weightf_t& w);
 
 struct shard_id_t {
   int8_t id;
@@ -572,13 +489,8 @@ struct shard_id_t {
     using ceph::decode;
     decode(id, bl);
   }
-  void dump(ceph::Formatter *f) const {
-    f->dump_int("id", id);
-  }
-  static void generate_test_instances(std::list<shard_id_t*>& ls) {
-    ls.push_back(new shard_id_t(1));
-    ls.push_back(new shard_id_t(2));
-  }
+  void dump(ceph::Formatter *f) const;
+  static void generate_test_instances(std::list<shard_id_t*>& ls);
   shard_id_t& operator++() { ++id; return *this; }
   friend constexpr std::strong_ordering operator<=>(const shard_id_t &lhs,
                                                     const shard_id_t &rhs) {
@@ -650,13 +562,8 @@ struct errorcode32_t {
     decode(newcode, bl);
     set_wire_to_host(newcode);
   }
-  void dump(ceph::Formatter *f) const {
-    f->dump_int("code", code);
-  }
-  static void generate_test_instances(std::list<errorcode32_t*>& ls) {
-    ls.push_back(new errorcode32_t(1));
-    ls.push_back(new errorcode32_t(2));
-  }
+  void dump(ceph::Formatter *f) const;
+  static void generate_test_instances(std::list<errorcode32_t*>& ls);
 };
 WRITE_CLASS_ENCODER(errorcode32_t)