|
20 | 20 | #include <string>
|
21 | 21 | #include <utility>
|
22 | 22 |
|
23 |
| -#include "arrow/util/double_conversion.h" |
| 23 | +#include "arrow/vendored/fast_float/fast_float.h" |
24 | 24 |
|
25 | 25 | namespace arrow {
|
26 | 26 | namespace internal {
|
27 | 27 |
|
28 |
| -namespace { |
29 |
| - |
30 |
| -struct StringToFloatConverterImpl { |
31 |
| - StringToFloatConverterImpl() |
32 |
| - : main_converter_(flags_, main_junk_value_, main_junk_value_, "inf", "nan"), |
33 |
| - fallback_converter_(flags_, fallback_junk_value_, fallback_junk_value_, "inf", |
34 |
| - "nan") {} |
35 |
| - |
36 |
| - // NOTE: This is only supported in double-conversion 3.1+ |
37 |
| - static constexpr int flags_ = |
38 |
| - util::double_conversion::StringToDoubleConverter::ALLOW_CASE_INSENSIBILITY; |
39 |
| - |
40 |
| - // Two unlikely values to signal a parsing error |
41 |
| - static constexpr double main_junk_value_ = 0.7066424364107089; |
42 |
| - static constexpr double fallback_junk_value_ = 0.40088499148279166; |
43 |
| - |
44 |
| - util::double_conversion::StringToDoubleConverter main_converter_; |
45 |
| - util::double_conversion::StringToDoubleConverter fallback_converter_; |
46 |
| -}; |
47 |
| - |
48 |
| -static const StringToFloatConverterImpl g_string_to_float; |
49 |
| - |
50 |
| -// Older clang versions need an explicit implementation definition. |
51 |
| -constexpr double StringToFloatConverterImpl::main_junk_value_; |
52 |
| -constexpr double StringToFloatConverterImpl::fallback_junk_value_; |
53 |
| - |
54 |
| -} // namespace |
55 |
| - |
56 | 28 | bool StringToFloat(const char* s, size_t length, float* out) {
|
57 |
| - int processed_length; |
58 |
| - float v; |
59 |
| - v = g_string_to_float.main_converter_.StringToFloat(s, static_cast<int>(length), |
60 |
| - &processed_length); |
61 |
| - if (ARROW_PREDICT_FALSE(v == static_cast<float>(g_string_to_float.main_junk_value_))) { |
62 |
| - v = g_string_to_float.fallback_converter_.StringToFloat(s, static_cast<int>(length), |
63 |
| - &processed_length); |
64 |
| - if (ARROW_PREDICT_FALSE(v == |
65 |
| - static_cast<float>(g_string_to_float.fallback_junk_value_))) { |
66 |
| - return false; |
67 |
| - } |
68 |
| - } |
69 |
| - *out = v; |
70 |
| - return true; |
| 29 | + const auto res = ::arrow_vendored::fast_float::from_chars(s, s + length, *out); |
| 30 | + return res.ec == std::errc() && res.ptr == s + length; |
71 | 31 | }
|
72 | 32 |
|
73 | 33 | bool StringToFloat(const char* s, size_t length, double* out) {
|
74 |
| - int processed_length; |
75 |
| - double v; |
76 |
| - v = g_string_to_float.main_converter_.StringToDouble(s, static_cast<int>(length), |
77 |
| - &processed_length); |
78 |
| - if (ARROW_PREDICT_FALSE(v == g_string_to_float.main_junk_value_)) { |
79 |
| - v = g_string_to_float.fallback_converter_.StringToDouble(s, static_cast<int>(length), |
80 |
| - &processed_length); |
81 |
| - if (ARROW_PREDICT_FALSE(v == g_string_to_float.fallback_junk_value_)) { |
82 |
| - return false; |
83 |
| - } |
84 |
| - } |
85 |
| - *out = v; |
86 |
| - return true; |
| 34 | + const auto res = ::arrow_vendored::fast_float::from_chars(s, s + length, *out); |
| 35 | + return res.ec == std::errc() && res.ptr == s + length; |
87 | 36 | }
|
88 | 37 |
|
89 | 38 | // ----------------------------------------------------------------------
|
|
0 commit comments