diff options
author | Billy Donahue <billy.donahue@mongodb.com> | 2019-07-08 16:59:45 -0400 |
---|---|---|
committer | Billy Donahue <billy.donahue@mongodb.com> | 2019-07-22 17:07:53 -0400 |
commit | be18bd1133d6f8118ebb79a2251c4a49b1c84ec1 (patch) | |
tree | e5f9fd119eb3938f8315620c01ac6905a37fdd80 /src/mongo/util/itoa.h | |
parent | 2455e412e3ee165e71ff6403ac33ac2e8f35d823 (diff) | |
download | mongo-be18bd1133d6f8118ebb79a2251c4a49b1c84ec1.tar.gz |
SERVER-42034 Optimize ItoA (~13% faster, remove the 1kLoC static table)
Diffstat (limited to 'src/mongo/util/itoa.h')
-rw-r--r-- | src/mongo/util/itoa.h | 17 |
1 files changed, 7 insertions, 10 deletions
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<uint64_t>::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<std::uint64_t>::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]; }; |