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] Minor tweaks to the facets and a speed-up


Hi,

this started as a very minor clean-up, but in the process I noticed that
we weren't calling reserve on the groupings string! So, for the money_get
test used during the last days:

string
======
current head - 4.770u 0.000s 0:04.92 96.9%     0+0k 0+0io 254pf+0w
patched head - 4.010u 0.010s 0:04.12 97.5%     0+0k 0+0io 255pf+0w
current 3.4  - 8.660u 0.000s 0:08.96 96.6%     0+0k 0+0io 253pf+0w

long double
===========
current head - 4.750u 0.020s 0:04.90 97.3%     0+0k 0+0io 262pf+0w
patched head - 4.140u 0.010s 0:04.26 97.4%     0+0k 0+0io 263pf+0w
current 3.4  - 9.400u 0.010s 0:09.67 97.3%     0+0k 0+0io 261pf+0w


Regtested x86-linux.


Paolo.

///////////////
2004-02-27  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/locale_facets.tcc (num_get<>::_M_extract_float,
	num_get<>::_M_extract_int, money_get<>::_M_extract): If appropriate,
	call reserve on the __tmp_gruping string.
	(num_get<>::_M_extract_float): Don't append unnecessarily a
	char() to the returned string.
	* include/bits/locale_facets.tcc: Trivial reformattings.
diff -urN libstdc++-v3-orig/include/bits/locale_facets.tcc libstdc++-v3/include/bits/locale_facets.tcc
--- libstdc++-v3-orig/include/bits/locale_facets.tcc	2004-02-27 09:43:20.000000000 +0100
+++ libstdc++-v3/include/bits/locale_facets.tcc	2004-02-27 12:25:10.000000000 +0100
@@ -219,9 +219,11 @@
       bool __found_dec = false;
       bool __found_sci = false;
       string __found_grouping;
+      if (__lc->_M_use_grouping)
+	__found_grouping.reserve(32);
       int __sep_pos = 0;
       bool __e;
-      const char_type* __p;
+      const char_type* __q;
       while (__beg != __end)
         {
 	  // According to 22.2.2.1.2, p8-9, first look for thousands_sep
@@ -265,9 +267,9 @@
 	      else
 		break;
 	    }
-          else if (__p = __traits_type::find(__lit + _S_izero, 10, __c))
+          else if (__q = __traits_type::find(__lit + _S_izero, 10, __c))
 	    {
-	      __xtrc += _S_atoms_in[__p - __lit];
+	      __xtrc += _S_atoms_in[__q - __lit];
 	      __found_mantissa = true;
 	      ++__sep_pos;
 	      ++__beg;
@@ -283,7 +285,8 @@
 	      // Remove optional plus or minus sign, if they exist.
 	      if (++__beg != __end)
 		{
-		  const bool __plus = __traits_type::eq(*__beg, __lit[_S_iplus]);
+		  const bool __plus = __traits_type::eq(*__beg,
+							__lit[_S_iplus]);
 		  if (__plus || __traits_type::eq(*__beg, __lit[_S_iminus]))
 		    {
 		      __xtrc += __plus ? _S_atoms_in[_S_iplus]
@@ -311,7 +314,6 @@
         }
 
       // Finish up.
-      __xtrc += char();
       if (__beg == __end)
         __err |= ios_base::eofbit;
       return __beg;
@@ -332,7 +334,8 @@
 	const _CharT* __lit = __lc->_M_atoms_in;
 
 	// NB: Iff __basefield == 0, __base can change based on contents.
-	const ios_base::fmtflags __basefield = __io.flags() & ios_base::basefield;
+	const ios_base::fmtflags __basefield = __io.flags()
+	                                       & ios_base::basefield;
 	const bool __oct = __basefield == ios_base::oct;
 	int __base = __oct ? 8 : (__basefield == ios_base::hex ? 16 : 10);
 
@@ -395,11 +398,13 @@
 
 	// Extract.
 	string __found_grouping;
+	if (__lc->_M_use_grouping)
+	  __found_grouping.reserve(32);
 	int __sep_pos = 0;
 	bool __overflow = false;
 	_ValueT __result = 0;
 	const char_type* __lit_zero = __lit + _S_izero;
-	const char_type* __p;
+	const char_type* __q;
 	if (__negative)
 	  {
 	    const _ValueT __min = numeric_limits<_ValueT>::min() / __base;
@@ -426,16 +431,17 @@
 		  }
 		else if (__traits_type::eq(__c, __lc->_M_decimal_point))
 		  break;
-		else if (__p = __traits_type::find(__lit_zero, __len, __c))
+		else if (__q = __traits_type::find(__lit_zero, __len, __c))
 		  {
-		    int __digit = __p - __lit_zero;
+		    int __digit = __q - __lit_zero;
 		    if (__digit > 15)
 		      __digit -= 6;
 		    if (__result < __min)
 		      __overflow = true;
 		    else
 		      {
-			const _ValueT __new_result = __result * __base - __digit;
+			const _ValueT __new_result = __result * __base
+			                             - __digit;
 			__overflow |= __new_result > __result;
 			__result = __new_result;
 			++__sep_pos;
@@ -469,16 +475,17 @@
 		  }
 		else if (__traits_type::eq(__c, __lc->_M_decimal_point))
 		  break;
-		else if (__p = __traits_type::find(__lit_zero, __len, __c))
+		else if (__q = __traits_type::find(__lit_zero, __len, __c))
 		  {
-		    int __digit = __p - __lit_zero;
+		    int __digit = __q - __lit_zero;
 		    if (__digit > 15)
 		      __digit -= 6;
 		    if (__result > __max)
 		      __overflow = true;
 		    else
 		      {
-			const _ValueT __new_result = __result * __base + __digit;
+			const _ValueT __new_result = __result * __base
+			                             + __digit;
 			__overflow |= __new_result < __result;
 			__result = __new_result;
 			++__sep_pos;
@@ -497,7 +504,8 @@
 	    // Add the ending grouping.
 	    __found_grouping += static_cast<char>(__sep_pos);
 
-	    if (!std::__verify_grouping(__lc->_M_grouping, __lc->_M_grouping_size,
+	    if (!std::__verify_grouping(__lc->_M_grouping,
+					__lc->_M_grouping_size,
 					__found_grouping))
 	      __err |= ios_base::failbit;
 	  }
@@ -890,8 +898,9 @@
   template<typename _CharT, typename _OutIter>
     void
     num_put<_CharT, _OutIter>::
-    _M_group_float(const char* __grouping, size_t __grouping_size, _CharT __sep,
-		   const _CharT* __p, _CharT* __new, _CharT* __cs, int& __len) const
+    _M_group_float(const char* __grouping, size_t __grouping_size,
+		   _CharT __sep, const _CharT* __p, _CharT* __new,
+		   _CharT* __cs, int& __len) const
     {
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
       // 282. What types does numpunct grouping refer to?
@@ -1061,8 +1070,9 @@
 	  const streamsize __w = __io.width();
 	  if (__w > static_cast<streamsize>(__len))
 	    {
-	      _CharT* __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
-								   * __w));
+	      _CharT* __cs
+		= static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
+							* __w));
 	      _M_pad(__fill, __w, __io, __cs, __name, __len);
 	      __name = __cs;
 	    }
@@ -1120,8 +1130,10 @@
            const void* __v) const
     {
       const ios_base::fmtflags __flags = __io.flags();
-      const ios_base::fmtflags __fmt = ~(ios_base::showpos | ios_base::basefield
-					 | ios_base::uppercase | ios_base::internal);
+      const ios_base::fmtflags __fmt = ~(ios_base::showpos
+					 | ios_base::basefield
+					 | ios_base::uppercase
+					 | ios_base::internal);
       __io.flags(__flags & __fmt | (ios_base::hex | ios_base::showbase));
 
       __s = _M_insert_int(__s, __io, __fill,
@@ -1186,6 +1198,8 @@
 	bool __long_sign = false;
 	// String of grouping info from thousands_sep plucked from __units.
 	string __grouping_tmp;
+	if (__lc->_M_use_grouping)
+	  __grouping_tmp.reserve(32);
 	// Marker for thousands_sep position.
 	int __sep_pos = 0;
 	// If input iterator is in a valid state.
@@ -1274,9 +1288,10 @@
 		      __sep_pos = 0;
 		      __testdecfound = true;
 		    }
-		  else if (*__beg == __lc->_M_thousands_sep && !__testdecfound)
+		  else if (__lc->_M_use_grouping
+			   && *__beg == __lc->_M_thousands_sep)
 		    {
-		      if (__lc->_M_grouping_size)
+		      if (!__testdecfound)
 			{
 			  // Mark position for later analysis.
 			  __grouping_tmp += static_cast<char>(__sep_pos);
@@ -2146,8 +2161,9 @@
       // NB: This size is arbitrary. Should this be a data member,
       // initialized at construction?
       const size_t __maxlen = 64;
-      char_type* __res = static_cast<char_type*>(__builtin_alloca(sizeof(char_type)
-								  * __maxlen));
+      char_type* __res =
+	static_cast<char_type*>(__builtin_alloca(sizeof(char_type)
+						 * __maxlen));
 
       // NB: In IEE 1003.1-200x, and perhaps other locale models, it
       // is possible that the format character will be longer than one

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