diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-02-13 21:20:48 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-02-13 21:20:48 +0000 |
commit | 17fa5fe2bd41e0b5ce38b11f2894f652290c5a1a (patch) | |
tree | 1e34b19b2dd9debafd60be4b8023c07dd88d138e /document | |
parent | 75527e1dea411fe4287369739663ab77d4d5984c (diff) |
Use faster std::from_chars instead of oldstyle strtoul.
Diffstat (limited to 'document')
-rw-r--r-- | document/src/vespa/document/base/idstring.cpp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/document/src/vespa/document/base/idstring.cpp b/document/src/vespa/document/base/idstring.cpp index be3a62b36a3..d684d135d87 100644 --- a/document/src/vespa/document/base/idstring.cpp +++ b/document/src/vespa/document/base/idstring.cpp @@ -5,8 +5,8 @@ #include <vespa/document/bucket/bucketid.h> #include <vespa/vespalib/util/md5.h> #include <vespa/vespalib/util/stringfmt.h> -#include <cerrno> #include <cstring> +#include <charconv> using vespalib::string; using vespalib::stringref; @@ -114,15 +114,14 @@ union LocationUnion { }; uint64_t -parseNumber(stringref number) { - char* errPos = nullptr; - errno = 0; - uint64_t n = strtoul(number.data(), &errPos, 10); - if (*errPos) [[unlikely]]{ - throw IdParseException("'n'-value must be a 64-bit number. It was " + number, VESPA_STRLOC); +parseNumber(stringref s) { + uint64_t n(0); + auto res = std::from_chars(s.data(), s.data() + s.size(), n, 10); + if (res.ptr != s.data() + s.size()) [[unlikely]]{ + throw IdParseException("'n'-value must be a 64-bit number. It was " + s, VESPA_STRLOC); } - if (errno == ERANGE) [[unlikely]] { - throw IdParseException("'n'-value out of range (" + number + ")", VESPA_STRLOC); + if (res.ec == std::errc::result_out_of_range) [[unlikely]] { + throw IdParseException("'n'-value out of range (" + s + ")", VESPA_STRLOC); } return n; } |