// vim: ts=8 sw=2 smarttab
#include <charconv>
+#include <fmt/compile.h>
+#include <fmt/core.h>
#include "hobject.h"
#include "common/Formatter.h"
using ceph::bufferlist;
using ceph::Formatter;
-static void append_escaped(const string &in, string *out)
+namespace {
+void escape_special_chars(const string& in, string* out)
{
- for (string::const_iterator i = in.begin(); i != in.end(); ++i) {
- if (*i == '%') {
+ for (auto c : in) {
+ if (c == '%') {
out->push_back('%');
out->push_back('p');
- } else if (*i == '.') {
+ } else if (c == '.') {
out->push_back('%');
out->push_back('e');
- } else if (*i == '_') {
+ } else if (c == '_') {
out->push_back('%');
out->push_back('u');
} else {
- out->push_back(*i);
+ out->push_back(c);
}
}
}
+} // namespace
set<string> hobject_t::get_prefixes(
uint32_t bits,
string hobject_t::to_str() const
{
- string out;
-
- char snap_with_hash[1000];
- char *t = snap_with_hash;
- const char *end = t + sizeof(snap_with_hash);
-
uint64_t poolid(pool);
- t += snprintf(t, end - t, "%.*llX", 16, (long long unsigned)poolid);
-
uint32_t revhash(get_nibblewise_key_u32());
- t += snprintf(t, end - t, ".%.*X", 8, revhash);
- if (snap == CEPH_NOSNAP)
- t += snprintf(t, end - t, ".head");
- else if (snap == CEPH_SNAPDIR)
- t += snprintf(t, end - t, ".snapdir");
- else
- t += snprintf(t, end - t, ".%llx", (long long unsigned)snap);
-
- out.append(snap_with_hash, t);
+ string out;
+ if (snap == CEPH_NOSNAP) {
+ out = fmt::format(FMT_COMPILE("{:016X}.{:08X}.head."), poolid, revhash);
+ } else if (snap == CEPH_SNAPDIR) {
+ out = fmt::format(FMT_COMPILE("{:016X}.{:08X}.snapdir."), poolid, revhash);
+ } else {
+ out = fmt::format(
+ FMT_COMPILE("{:016X}.{:08X}.{:X}."), poolid, revhash,
+ (unsigned long long)snap);
+ }
+ escape_special_chars(oid.name, &out);
out.push_back('.');
- append_escaped(oid.name, &out);
- out.push_back('.');
- append_escaped(get_key(), &out);
+ escape_special_chars(get_key(), &out);
out.push_back('.');
- append_escaped(nspace, &out);
+ escape_special_chars(nspace, &out);
return out;
}
void dump(ceph::Formatter *f) const;
static void generate_test_instances(std::list<hobject_t*>& o);
friend int cmp(const hobject_t& l, const hobject_t& r);
- auto operator<=>(const hobject_t &rhs) const noexcept {
+ constexpr auto operator<=>(const hobject_t &rhs) const noexcept {
auto cmp = max <=> rhs.max;
if (cmp != 0) return cmp;
cmp = pool <=> rhs.pool;
if (cmp != 0) return cmp;
return snap <=> rhs.snap;
}
- bool operator==(const hobject_t& rhs) const noexcept {
+ constexpr bool operator==(const hobject_t& rhs) const noexcept {
return operator<=>(rhs) == 0;
}
friend struct ghobject_t;
void dump(ceph::Formatter *f) const;
static void generate_test_instances(std::list<ghobject_t*>& o);
friend int cmp(const ghobject_t& l, const ghobject_t& r);
- auto operator<=>(const ghobject_t&) const = default;
+ constexpr auto operator<=>(const ghobject_t&) const = default;
bool operator==(const ghobject_t&) const = default;
};
WRITE_CLASS_ENCODER(ghobject_t)