Using fmtlib, and treating the size of uint64_t as a known
quantity.
Per google-bench - the new version is 10% to 20% faster.
Signed-off-by: Ronen Friedman <rfriedma@redhat.com>
*/
#include "SnapMapper.h"
+#include <fmt/printf.h>
#define dout_context cct
#define dout_subsys ceph_subsys_osd
string SnapMapper::get_prefix(int64_t pool, snapid_t snap)
{
- char buf[100];
- int len = snprintf(
- buf, sizeof(buf),
- "%lld_%.*X_",
- (long long)pool,
- (int)(sizeof(snap)*2), static_cast<unsigned>(snap));
- return MAPPING_PREFIX + string(buf, len);
+ static_assert(sizeof(pool) == 8, "assumed by the formatting code");
+ return fmt::sprintf("%s%lld_%.16X_",
+ MAPPING_PREFIX,
+ pool,
+ snap);
}
string SnapMapper::to_raw_key(