[libcxx] r194080 - Refactor floating point code for num_get::do_get into a template. No functionality change

Marshall Clow mclow.lists at gmail.com
Tue Nov 5 06:28:52 PST 2013


Author: marshall
Date: Tue Nov  5 08:28:52 2013
New Revision: 194080

URL: http://llvm.org/viewvc/llvm-project?rev=194080&view=rev
Log:
Refactor floating point code for num_get::do_get into a template. No functionality change

Modified:
    libcxx/trunk/include/locale

Modified: libcxx/trunk/include/locale
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/locale?rev=194080&r1=194079&r2=194080&view=diff
==============================================================================
--- libcxx/trunk/include/locale (original)
+++ libcxx/trunk/include/locale Tue Nov  5 08:28:52 2013
@@ -813,6 +813,11 @@ protected:
                              ios_base::iostate& __err, long double& __v) const;
     virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
                              ios_base::iostate& __err, void*& __v) const;
+
+    template <class _Fp>
+    iter_type __do_get_floating_point
+                            (iter_type __b, iter_type __e, ios_base& __iob,
+                             ios_base::iostate& __err, _Fp& __v) const;
 };
 
 template <class _CharT, class _InputIterator>
@@ -1234,12 +1239,15 @@ num_get<_CharT, _InputIterator>::do_get(
     return __b;
 }
 
+// floating point
+
 template <class _CharT, class _InputIterator>
+template <class _Fp>
 _InputIterator
-num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
+num_get<_CharT, _InputIterator>::__do_get_floating_point(iter_type __b, iter_type __e,
                                         ios_base& __iob,
                                         ios_base::iostate& __err,
-                                        float& __v) const
+                                        _Fp& __v) const
 {
     // Stage 1, nothing to do
     // Stage 2
@@ -1277,7 +1285,7 @@ num_get<_CharT, _InputIterator>::do_get(
     if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz)
         *__g_end++ = __dc;
     // Stage 3
-    __v = __num_get_float<float>(__a, __a_end, __err);
+    __v = __num_get_float<_Fp>(__a, __a_end, __err);
     // Digit grouping checked
     __check_grouping(__grouping, __g, __g_end, __err);
     // EOF checked
@@ -1291,51 +1299,19 @@ _InputIterator
 num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
                                         ios_base& __iob,
                                         ios_base::iostate& __err,
+                                        float& __v) const
+{
+    return this->__do_get_floating_point(__b, __e, __iob, __err, __v );
+}
+
+template <class _CharT, class _InputIterator>
+_InputIterator
+num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
+                                        ios_base& __iob,
+                                        ios_base::iostate& __err,
                                         double& __v) const
 {
-    // Stage 1, nothing to do
-    // Stage 2
-    char_type __atoms[32];
-    char_type __decimal_point;
-    char_type __thousands_sep;
-    string __grouping = this->__stage2_float_prep(__iob, __atoms,
-                                                  __decimal_point,
-                                                  __thousands_sep);
-    string __buf;
-    __buf.resize(__buf.capacity());
-    char* __a = &__buf[0];
-    char* __a_end = __a;
-    unsigned __g[__num_get_base::__num_get_buf_sz];
-    unsigned* __g_end = __g;
-    unsigned __dc = 0;
-    bool __in_units = true;
-    char __exp = 'E';
-    for (; __b != __e; ++__b)
-    {
-        if (__a_end - __a == __buf.size())
-        {
-            size_t __tmp = __buf.size();
-            __buf.resize(2*__buf.size());
-            __buf.resize(__buf.capacity());
-            __a = &__buf[0];
-            __a_end = __a + __tmp;
-        }
-        if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end,
-                                      __decimal_point, __thousands_sep,
-                                      __grouping, __g, __g_end,
-                                      __dc, __atoms))
-            break;
-    }
-    if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz)
-        *__g_end++ = __dc;
-    // Stage 3
-    __v = __num_get_float<double>(__a, __a_end, __err);
-    // Digit grouping checked
-    __check_grouping(__grouping, __g, __g_end, __err);
-    // EOF checked
-    if (__b == __e)
-        __err |= ios_base::eofbit;
-    return __b;
+    return this->__do_get_floating_point(__b, __e, __iob, __err, __v );
 }
 
 template <class _CharT, class _InputIterator>
@@ -1345,49 +1321,7 @@ num_get<_CharT, _InputIterator>::do_get(
                                         ios_base::iostate& __err,
                                         long double& __v) const
 {
-    // Stage 1, nothing to do
-    // Stage 2
-    char_type __atoms[32];
-    char_type __decimal_point;
-    char_type __thousands_sep;
-    string __grouping = this->__stage2_float_prep(__iob, __atoms,
-                                                  __decimal_point,
-                                                  __thousands_sep);
-    string __buf;
-    __buf.resize(__buf.capacity());
-    char* __a = &__buf[0];
-    char* __a_end = __a;
-    unsigned __g[__num_get_base::__num_get_buf_sz];
-    unsigned* __g_end = __g;
-    unsigned __dc = 0;
-    bool __in_units = true;
-    char __exp = 'E';
-    for (; __b != __e; ++__b)
-    {
-        if (__a_end - __a == __buf.size())
-        {
-            size_t __tmp = __buf.size();
-            __buf.resize(2*__buf.size());
-            __buf.resize(__buf.capacity());
-            __a = &__buf[0];
-            __a_end = __a + __tmp;
-        }
-        if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end,
-                                      __decimal_point, __thousands_sep,
-                                      __grouping, __g, __g_end,
-                                      __dc, __atoms))
-            break;
-    }
-    if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz)
-        *__g_end++ = __dc;
-    // Stage 3
-    __v = __num_get_float<long double>(__a, __a_end, __err);
-    // Digit grouping checked
-    __check_grouping(__grouping, __g, __g_end, __err);
-    // EOF checked
-    if (__b == __e)
-        __err |= ios_base::eofbit;
-    return __b;
+    return this->__do_get_floating_point(__b, __e, __iob, __err, __v );
 }
 
 template <class _CharT, class _InputIterator>





More information about the cfe-commits mailing list