mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
make code branchless (#2546)
This commit is contained in:
+4
-10
@@ -814,20 +814,14 @@ void grisu2(char *buf, int &len, int &decimal_exponent, FloatType value) {
|
||||
*/
|
||||
inline char *append_exponent(char *buf, int e) {
|
||||
|
||||
if (e < 0) {
|
||||
e = -e;
|
||||
*buf++ = '-';
|
||||
} else {
|
||||
*buf++ = '+';
|
||||
}
|
||||
bool isNegative = e < 0;
|
||||
e = isNegative ? -e : e;
|
||||
*buf++ = isNegative ? '-' : '+';
|
||||
|
||||
auto k = static_cast<std::uint32_t>(e);
|
||||
if (k < 10) {
|
||||
if (k < 100) {
|
||||
// Always print at least two digits in the exponent.
|
||||
// This is for compatibility with printf("%g").
|
||||
*buf++ = '0';
|
||||
*buf++ = static_cast<char>('0' + k);
|
||||
} else if (k < 100) {
|
||||
*buf++ = static_cast<char>('0' + k / 10);
|
||||
k %= 10;
|
||||
*buf++ = static_cast<char>('0' + k);
|
||||
|
||||
Reference in New Issue
Block a user