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

@ -217,7 +217,7 @@ public:
//char* tmp_val = reinterpret_cast<char*>(0x01);
ARROW_RETURN_NOT_OK(builder.Append(""));
} else {
ARROW_RETURN_NOT_OK(builder.Append(string_val->to_string()));
ARROW_RETURN_NOT_OK(builder.Append(string_val->ptr, string_val->len));
}
break;
}
@ -230,12 +230,9 @@ public:
break;
}
case TYPE_LARGEINT: {
char buf[48];
int len = 48;
char* v = LargeIntValue::to_string(
reinterpret_cast<const PackedInt128*>(cell_ptr)->value, buf, &len);
std::string temp(v, len);
ARROW_RETURN_NOT_OK(builder.Append(std::move(temp)));
auto string_temp = LargeIntValue::to_string(
reinterpret_cast<const PackedInt128*>(cell_ptr)->value);
ARROW_RETURN_NOT_OK(builder.Append(string_temp.data(), string_temp.size()));
break;
}
default: {

View File

@ -55,18 +55,11 @@ uint24_t timestamp_from_date(const std::string& date_str) {
}
std::string time_str_from_double(double time) {
std::stringstream time_ss;
if (time < 0) {
time_ss << "-";
time = -time;
return fmt::format("-{:02d}:{:02d}:{:02d}", (int64_t)(time / 60 / 60), ((int64_t)(time / 60)) % 60, ((int64_t)time) % 60);
}
int64_t hour = time / 60 / 60;
int minute = ((int64_t)(time / 60)) % 60;
int second = ((int64_t)time) % 60;
time_ss << std::setw(2) << std::setfill('0') << hour << ":" << std::setw(2) << std::setfill('0')
<< minute << ":" << std::setw(2) << std::setfill('0') << second;
return time_ss.str();
return fmt::format("{:02d}:{:02d}:{:02d}", (int64_t)(time / 60 / 60), ((int64_t)(time / 60)) % 60, ((int64_t)time) % 60);
}
} // namespace doris