Use fmt and std::from_chars to make convert integer to string and convert string to integer more efficient (#6361)

* [Optimize] optimize the speed of converting integer to string

* Use fmt and std::from_chars to make convert integer to string and convert string to integer more efficient

Co-authored-by: caiconghui <caiconghui@xiaomi.com>
This commit is contained in:
caiconghui
2021-08-04 10:55:19 +08:00
committed by GitHub
parent 16bc5fa585
commit d1007afe80
11 changed files with 71 additions and 123 deletions

View File

@ -26,20 +26,8 @@ namespace doris {
std::ostream& operator<<(std::ostream& os, __int128 const& value) {
std::ostream::sentry s(os);
if (s) {
unsigned __int128 tmp = value < 0 ? -value : value;
char buffer[48];
char* d = std::end(buffer);
do {
--d;
*d = "0123456789"[tmp % 10];
tmp /= 10;
} while (tmp != 0);
if (value < 0) {
--d;
*d = '-';
}
int len = std::end(buffer) - d;
if (os.rdbuf()->sputn(d, len) != len) {
std::string value_str = fmt::format("{}", value);
if (os.rdbuf()->sputn(value_str.data(), value_str.size()) != value_str.size()) {
os.setstate(std::ios_base::badbit);
}
}