From be18bd1133d6f8118ebb79a2251c4a49b1c84ec1 Mon Sep 17 00:00:00 2001 From: Billy Donahue Date: Mon, 8 Jul 2019 16:59:45 -0400 Subject: SERVER-42034 Optimize ItoA (~13% faster, remove the 1kLoC static table) --- src/mongo/util/itoa.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'src/mongo/util/itoa.h') diff --git a/src/mongo/util/itoa.h b/src/mongo/util/itoa.h index 37451847a95..878bd62d3b6 100644 --- a/src/mongo/util/itoa.h +++ b/src/mongo/util/itoa.h @@ -41,23 +41,20 @@ namespace mongo { * and only really should be used in hot code paths. */ class ItoA { - ItoA(const ItoA&) = delete; - ItoA& operator=(const ItoA&) = delete; - public: - static constexpr size_t kBufSize = std::numeric_limits::digits10 // - + 1 // digits10 is 1 less than the maximum number of digits. - + 1; // NUL byte. + // digits10 is 1 less than the maximum number of digits. + static constexpr size_t kBufSize = std::numeric_limits::digits10 + 1; explicit ItoA(std::uint64_t i); + ItoA(const ItoA&) = delete; + ItoA& operator=(const ItoA&) = delete; - operator StringData() { - return {_str, _len}; + operator StringData() const { + return _str; } private: - const char* _str{nullptr}; - std::size_t _len{0}; + StringData _str; char _buf[kBufSize]; }; -- cgit v1.2.1