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] Tweak a bit the fix for 16678


Hi,

traits_type::find is very high in the profile and we had better computing
it only when really necessary.

Tested x86-linux.

Paolo.

////////////////
2004-07-30  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/locale_facets.tcc (num_get<>::_M_extract_float,
	num_get<>::_M_extract_int): In the main parsing loop delay the
	life and evaluation of __q to the actual use point.
diff -prN libstdc++-v3-orig/include/bits/locale_facets.tcc libstdc++-v3/include/bits/locale_facets.tcc
*** libstdc++-v3-orig/include/bits/locale_facets.tcc	Fri Jul 30 01:13:42 2004
--- libstdc++-v3/include/bits/locale_facets.tcc	Fri Jul 30 16:25:18 2004
*************** namespace std
*** 330,336 ****
  	  // According to 22.2.2.1.2, p8-9, first look for thousands_sep
  	  // and decimal_point.
  	  const char_type __c = *__beg;
- 	  const char_type* __q = __traits_type::find(__lit_zero, 10, __c);
            if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep)
  	    {
  	      if (!__found_dec && !__found_sci)
--- 330,335 ----
*************** namespace std
*** 368,407 ****
  	      else
  		break;
  	    }
!           else if (__q != 0)
  	    {
! 	      __xtrc += __num_base::_S_atoms_in[__q - __lit];
! 	      __found_mantissa = true;
! 	      ++__sep_pos;
! 	      ++__beg;
! 	    }
! 	  else if ((__c == __lit[__num_base::_S_ie] 
! 		    || __c == __lit[__num_base::_S_iE])
! 		   && __found_mantissa && !__found_sci)
! 	    {
! 	      // Scientific notation.
! 	      if (__found_grouping.size() && !__found_dec)
! 		__found_grouping += static_cast<char>(__sep_pos);
! 	      __xtrc += 'e';
! 	      __found_sci = true;
! 
! 	      // Remove optional plus or minus sign, if they exist.
! 	      if (++__beg != __end)
  		{
! 		  const bool __plus = *__beg == __lit[__num_base::_S_iplus];
! 		  if ((__plus || *__beg == __lit[__num_base::_S_iminus])
! 		      && !(__lc->_M_use_grouping
! 			   && *__beg == __lc->_M_thousands_sep)
! 		      && !(*__beg == __lc->_M_decimal_point))
  		    {
! 		      __xtrc += __plus ? '+' : '-';
! 		      ++__beg;
  		    }
  		}
  	    }
- 	  else
- 	    // Not a valid input item.
- 	    break;
          }
  
        // Digit grouping is checked. If grouping and found_grouping don't
--- 367,410 ----
  	      else
  		break;
  	    }
!           else
  	    {
! 	      const char_type* __q = __traits_type::find(__lit_zero, 10, __c);
! 	      if (__q)
  		{
! 		  __xtrc += __num_base::_S_atoms_in[__q - __lit];
! 		  __found_mantissa = true;
! 		  ++__sep_pos;
! 		  ++__beg;
! 		}
! 	      else if ((__c == __lit[__num_base::_S_ie] 
! 			|| __c == __lit[__num_base::_S_iE])
! 		       && __found_mantissa && !__found_sci)
! 		{
! 		  // Scientific notation.
! 		  if (__found_grouping.size() && !__found_dec)
! 		    __found_grouping += static_cast<char>(__sep_pos);
! 		  __xtrc += 'e';
! 		  __found_sci = true;
! 
! 		  // Remove optional plus or minus sign, if they exist.
! 		  if (++__beg != __end)
  		    {
! 		      const bool __plus = *__beg == __lit[__num_base::_S_iplus];
! 		      if ((__plus || *__beg == __lit[__num_base::_S_iminus])
! 			  && !(__lc->_M_use_grouping
! 			       && *__beg == __lc->_M_thousands_sep)
! 			  && !(*__beg == __lc->_M_decimal_point))
! 			{
! 			  __xtrc += __plus ? '+' : '-';
! 			  ++__beg;
! 			}
  		    }
  		}
+ 	      else
+ 		// Not a valid input item.
+ 		break;
  	    }
          }
  
        // Digit grouping is checked. If grouping and found_grouping don't
*************** namespace std
*** 516,523 ****
  		// According to 22.2.2.1.2, p8-9, first look for thousands_sep
  		// and decimal_point.
  		const char_type __c = *__beg;
- 		const char_type* __q = __traits_type::find(__lit_zero, 
- 							   __len, __c);
  		if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep)
  		  {
  		    // NB: Thousands separator at the beginning of a string
--- 519,524 ----
*************** namespace std
*** 535,560 ****
  		  }
  		else if (__c == __lc->_M_decimal_point)
  		  break;
! 		else if (__q != 0)
  		  {
! 		    int __digit = __q - __lit_zero;
! 		    if (__digit > 15)
! 		      __digit -= 6;
! 		    if (__result < __min)
! 		      __overflow = true;
! 		    else
  		      {
! 			const _ValueT __new_result = __result * __base
! 			                             - __digit;
! 			__overflow |= __new_result > __result;
! 			__result = __new_result;
! 			++__sep_pos;
! 			__found_num = true;
  		      }
  		  }
- 		else
- 		  // Not a valid input item.
- 		  break;
  	      }
  	  }
  	else
--- 536,566 ----
  		  }
  		else if (__c == __lc->_M_decimal_point)
  		  break;
! 		else
  		  {
! 		    const char_type* __q = __traits_type::find(__lit_zero, 
! 							       __len, __c);
! 		    if (__q)
  		      {
! 			int __digit = __q - __lit_zero;
! 			if (__digit > 15)
! 			  __digit -= 6;
! 			if (__result < __min)
! 			  __overflow = true;
! 			else
! 			  {
! 			    const _ValueT __new_result = (__result * __base
! 							  - __digit);
! 			    __overflow |= __new_result > __result;
! 			    __result = __new_result;
! 			    ++__sep_pos;
! 			    __found_num = true;
! 			  }
  		      }
+ 		    else
+ 		      // Not a valid input item.
+ 		      break;
  		  }
  	      }
  	  }
  	else
*************** namespace std
*** 563,570 ****
  	    for (; __beg != __end; ++__beg)
  	      {
  		const char_type __c = *__beg;
- 		const char_type* __q = __traits_type::find(__lit_zero, 
- 							   __len, __c);
  		if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep)
  		  {
  		    if (__sep_pos)
--- 569,574 ----
*************** namespace std
*** 580,604 ****
  		  }
  		else if (__c == __lc->_M_decimal_point)
  		  break;
! 		else if (__q != 0)
  		  {
! 		    int __digit = __q - __lit_zero;
! 		    if (__digit > 15)
! 		      __digit -= 6;
! 		    if (__result > __max)
! 		      __overflow = true;
! 		    else
  		      {
! 			const _ValueT __new_result = __result * __base
! 			                             + __digit;
! 			__overflow |= __new_result < __result;
! 			__result = __new_result;
! 			++__sep_pos;
! 			__found_num = true;
  		      }
  		  }
- 		else
- 		  break;
  	      }
  	  }
  
--- 584,613 ----
  		  }
  		else if (__c == __lc->_M_decimal_point)
  		  break;
! 		else
  		  {
! 		    const char_type* __q = __traits_type::find(__lit_zero,
! 							       __len, __c);    
! 		    if (__q)
  		      {
! 			int __digit = __q - __lit_zero;
! 			if (__digit > 15)
! 			  __digit -= 6;
! 			if (__result > __max)
! 			  __overflow = true;
! 			else
! 			  {
! 			    const _ValueT __new_result = (__result * __base
! 							  + __digit);
! 			    __overflow |= __new_result < __result;
! 			    __result = __new_result;
! 			    ++__sep_pos;
! 			    __found_num = true;
! 			  }
  		      }
+ 		    else
+ 		      break;
  		  }
  	      }
  	  }
  

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