This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] "World cup" patch to num_put


Hi,

tested x86-linux, dedicated to "Ringhio" Gattuso ;) , committed to mainline.

Paolo.

////////////////
2006-07-09  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/locale_facets.tcc (__int_to_char<>(_CharT*,
	long, const _CharT*, ios_base::fmtflags), __int_to_char<>(_CharT*,
	unsigned long, const _CharT*, ios_base::fmtflags),
	__int_to_char<>(_CharT*, long long, const _CharT*, ios_base::fmtflags),
	__int_to_char<>(_CharT*, unsigned long long, const _CharT*,
	ios_base::fmtflags)): Remove.
	(__int_to_char<>(_CharT*, _ValueT, const _CharT*, ios_base::fmtflags,
	bool)): Adjust.
	(num_put<>::_M_insert_int(_OutIter, ios_base&, _CharT, _ValueT)):
	Likewise.
Index: include/bits/locale_facets.tcc
===================================================================
--- include/bits/locale_facets.tcc	(revision 115296)
+++ include/bits/locale_facets.tcc	(working copy)
@@ -925,60 +925,13 @@
 
 _GLIBCXX_END_LDBL_NAMESPACE
 
-  // Forwarding functions to peel signed from unsigned integer types and
-  // either cast or compute the absolute value for the former, depending
-  // on __basefield.
-  template<typename _CharT>
-    inline int
-    __int_to_char(_CharT* __bufend, long __v, const _CharT* __lit,
-		  ios_base::fmtflags __flags)
-    {
-      unsigned long __ul = __v;
-      const ios_base::fmtflags __basefield = __flags & ios_base::basefield;
-      if (__builtin_expect(__basefield != ios_base::oct
-			   && __basefield != ios_base::hex, true))
-	__ul = __v < 0 ? -__v : __ul;
-      return __int_to_char(__bufend, __ul, __lit, __flags, false);
-    }
-
-  template<typename _CharT>
-    inline int
-    __int_to_char(_CharT* __bufend, unsigned long __v, const _CharT* __lit,
-		  ios_base::fmtflags __flags)
-    { return __int_to_char(__bufend, __v, __lit, __flags, false); }
-
-#ifdef _GLIBCXX_USE_LONG_LONG
-  template<typename _CharT>
-    inline int
-    __int_to_char(_CharT* __bufend, long long __v, const _CharT* __lit,
-		  ios_base::fmtflags __flags)
-    {
-      unsigned long long __ull = __v;
-      const ios_base::fmtflags __basefield = __flags & ios_base::basefield;
-      if (__builtin_expect(__basefield != ios_base::oct
-			   && __basefield != ios_base::hex, true))
-	__ull = __v < 0 ? -__v : __ull;
-      return __int_to_char(__bufend, __ull, __lit, __flags, false);
-    }
-
-  template<typename _CharT>
-    inline int
-    __int_to_char(_CharT* __bufend, unsigned long long __v, 
-		  const _CharT* __lit, ios_base::fmtflags __flags)
-    { return __int_to_char(__bufend, __v, __lit, __flags, false); }
-#endif
-
-  // N.B. The last argument is currently unused (see libstdc++/20914).
   template<typename _CharT, typename _ValueT>
     int
     __int_to_char(_CharT* __bufend, _ValueT __v, const _CharT* __lit,
-		  ios_base::fmtflags __flags, bool)
+		  ios_base::fmtflags __flags, bool __dec)
     {
-      const ios_base::fmtflags __basefield = __flags & ios_base::basefield;
       _CharT* __buf = __bufend;
-
-      if (__builtin_expect(__basefield != ios_base::oct
-			   && __basefield != ios_base::hex, true))
+      if (__builtin_expect(__dec, true))
 	{
 	  // Decimal.
 	  do
@@ -988,7 +941,7 @@
 	    }
 	  while (__v != 0);
 	}
-      else if (__basefield == ios_base::oct)
+      else if ((__flags & ios_base::basefield) == ios_base::oct)
 	{
 	  // Octal.
 	  do
@@ -1034,7 +987,8 @@
       _M_insert_int(_OutIter __s, ios_base& __io, _CharT __fill,
 		    _ValueT __v) const
       {
-	typedef __numpunct_cache<_CharT>	        __cache_type;
+	typedef typename __to_unsigned_type<_ValueT>::__type __unsigned_type;
+	typedef __numpunct_cache<_CharT>	             __cache_type;
 	__use_cache<__cache_type> __uc;
 	const locale& __loc = __io._M_getloc();
 	const __cache_type* __lc = __uc(__loc);
@@ -1048,7 +1002,11 @@
 
 	// [22.2.2.2.2] Stage 1, numeric conversion to character.
 	// Result is returned right-justified in the buffer.
-	int __len = __int_to_char(__cs + __ilen, __v, __lit, __flags);
+	const ios_base::fmtflags __basefield = __flags & ios_base::basefield;
+	const bool __dec = (__basefield != ios_base::oct
+			    && __basefield != ios_base::hex);
+	const __unsigned_type __u = (__v > 0 || !__dec) ? __v : -__v;
+ 	int __len = __int_to_char(__cs + __ilen, __u, __lit, __flags, __dec);
 	__cs += __ilen - __len;
 
 	// Add grouping, if necessary.
@@ -1065,9 +1023,7 @@
 	  }
 
 	// Complete Stage 1, prepend numeric base or sign.
-	const ios_base::fmtflags __basefield = __flags & ios_base::basefield;
-	if (__builtin_expect(__basefield != ios_base::oct
-			     && __basefield != ios_base::hex, true))
+	if (__builtin_expect(__dec, true))
 	  {
 	    // Decimal.
 	    if (__v > 0)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]