From: Sage Weil Date: Tue, 8 Mar 2016 16:21:42 +0000 (-0500) Subject: Merge pull request #7121 from efirs/ef_eversion_t_no_sprintf X-Git-Tag: v10.1.0~208 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=46007d271f9f604648eda0abceefb60de18d2f86;p=ceph.git Merge pull request #7121 from efirs/ef_eversion_t_no_sprintf osd: Replace snprintf with faster implementation in eversion_t::get_key_name Reviewed-by: Kefu Chai --- 46007d271f9f604648eda0abceefb60de18d2f86 diff --cc src/common/strtol.h index ed8656847ee7,6beee23d2cf2..2f4c4ce2756d --- a/src/common/strtol.h +++ b/src/common/strtol.h @@@ -31,7 -31,43 +31,29 @@@ float strict_strtof(const char *str, st uint64_t strict_sistrtoll(const char *str, std::string *err); -template -Target strict_si_cast(const char *str, std::string *err) { - uint64_t ret = strict_sistrtoll(str, err); - if (!err->empty()) - return ret; - if (ret > (uint64_t)std::numeric_limits::max()) { - err->append("The option value '"); - err->append(str); - err->append("' seems to be too large"); - return 0; - } - return ret; -} - -template <> -uint64_t strict_si_cast(const char *str, std::string *err); +template +T strict_si_cast(const char *str, std::string *err); + /* On enter buf points to the end of the buffer, e.g. where the least + * significant digit of the input number will be printed. Returns pointer to + * where the most significant digit were printed, including zero padding. + * Does NOT add zero at the end of buffer, this is responsibility of the caller. + */ + template + static inline + char* ritoa(T u, char *buf) + { + static_assert(std::is_unsigned::value, "signed types are not supported"); + static_assert(base <= 16, "extend character map below to support higher bases"); + unsigned digits = 0; + while (u) { + *--buf = "0123456789abcdef"[u % base]; + u /= base; + digits++; + } + while (digits++ < width) + *--buf = '0'; + return buf; + } + #endif