Move buffer and buffer_pos down (#125)
* Move buffer and buffer_pos down
Simplifies code by removing two asserts
Optimize code with -ftrivial-auto-var-init=pattern by avoiding initialization when buffer is not used
* Disable -ftrivial-auto-var-init=pattern for a large buffer
diff --git a/double-conversion/string-to-double.cc b/double-conversion/string-to-double.cc
index d7f7a4a..12b88f9 100644
--- a/double-conversion/string-to-double.cc
+++ b/double-conversion/string-to-double.cc
@@ -441,11 +441,6 @@
}
}
- // The longest form of simplified number is: "-<significant digits>.1eXXX\0".
- const int kBufferSize = kMaxSignificantDigits + 10;
- char buffer[kBufferSize]; // NOLINT: size is known at compile time.
- int buffer_pos = 0;
-
// Exponent will be adjusted if insignificant digits of the integer part
// or insignificant leading zeros of the fractional part are dropped.
int exponent = 0;
@@ -480,7 +475,6 @@
return junk_string_value_;
}
- DOUBLE_CONVERSION_ASSERT(buffer_pos == 0);
*processed_characters_count = static_cast<int>(current - input);
return sign ? -Double::Infinity() : Double::Infinity();
}
@@ -499,7 +493,6 @@
return junk_string_value_;
}
- DOUBLE_CONVERSION_ASSERT(buffer_pos == 0);
*processed_characters_count = static_cast<int>(current - input);
return sign ? -Double::NaN() : Double::NaN();
}
@@ -556,6 +549,12 @@
bool octal = leading_zero && (flags_ & ALLOW_OCTALS) != 0;
+ // The longest form of simplified number is: "-<significant digits>.1eXXX\0".
+ const int kBufferSize = kMaxSignificantDigits + 10;
+ DOUBLE_CONVERSION_STACK_UNINITIALIZED char
+ buffer[kBufferSize]; // NOLINT: size is known at compile time.
+ int buffer_pos = 0;
+
// Copy significant digits of the integer part (if any) to the buffer.
while (*current >= '0' && *current <= '9') {
if (significant_digits < kMaxSignificantDigits) {
diff --git a/double-conversion/utils.h b/double-conversion/utils.h
index 5393baa..471c3da 100644
--- a/double-conversion/utils.h
+++ b/double-conversion/utils.h
@@ -64,6 +64,12 @@
#endif
#endif
+#if defined(__clang__) && __has_attribute(uninitialized)
+#define DOUBLE_CONVERSION_STACK_UNINITIALIZED __attribute__((uninitialized))
+#else
+#define DOUBLE_CONVERSION_STACK_UNINITIALIZED
+#endif
+
// Double operations detection based on target architecture.
// Linux uses a 80bit wide floating point stack on x86. This induces double
// rounding, which in turn leads to wrong results.