bkietz commented on a change in pull request #7901: URL: https://github.com/apache/arrow/pull/7901#discussion_r465751971
########## File path: cpp/src/arrow/util/formatting.cc ########## @@ -36,38 +31,29 @@ const char digit_pairs[] = "6061626364656667686970717273747576777879" "8081828384858687888990919293949596979899"; -} // namespace detail - -struct FloatToStringFormatter::Impl { - Impl() - : converter_(DoubleToStringConverter::EMIT_POSITIVE_EXPONENT_SIGN, "inf", "nan", - 'e', -6, 10, 6, 0) {} - - DoubleToStringConverter converter_; -}; - -FloatToStringFormatter::FloatToStringFormatter() : impl_(new Impl()) {} +using util::double_conversion::DoubleToStringConverter; -FloatToStringFormatter::~FloatToStringFormatter() {} +static DoubleToStringConverter g_double_converter( + DoubleToStringConverter::EMIT_POSITIVE_EXPONENT_SIGN, "inf", "nan", 'e', -6, 10, 6, + 0); -int FloatToStringFormatter::FormatFloat(float v, char* out_buffer, int out_size) { - DCHECK_GE(out_size, kMinBufferSize); +int FormatFloat(float v, size_t buffer_size, char* buffer) { // StringBuilder checks bounds in debug mode for us - util::double_conversion::StringBuilder builder(out_buffer, out_size); - bool result = impl_->converter_.ToShortestSingle(v, &builder); + util::double_conversion::StringBuilder builder(buffer, static_cast<int>(buffer_size)); + bool result = g_double_converter.ToShortestSingle(v, &builder); DCHECK(result); ARROW_UNUSED(result); return builder.position(); } -int FloatToStringFormatter::FormatFloat(double v, char* out_buffer, int out_size) { - DCHECK_GE(out_size, kMinBufferSize); - util::double_conversion::StringBuilder builder(out_buffer, out_size); - bool result = impl_->converter_.ToShortest(v, &builder); +int FormatFloat(double v, size_t buffer_size, char* buffer) { + util::double_conversion::StringBuilder builder(buffer, static_cast<int>(buffer_size)); + bool result = g_double_converter.ToShortest(v, &builder); DCHECK(result); ARROW_UNUSED(result); return builder.position(); } +} // namespace detail Review comment: These aren't quite private; they're exported on line 220 of formatting.h so that they can be used by `FormatValueTraits<floating types>::Convert` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org