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] Speed-up ctype::do_is(mask, wchar_t) in the common case


Hi,

the below is what I'm going to commit after further testing for this
performance issue, explained on the libstdc++-v3 mailing list. Wrt the
preliminary patch posted there I'm also improving the treatment of the
other elementary masks, besides ctype_base::space.

Tested x86-linux.

Paolo.

//////////////
2005-07-18  Paolo Carlini  <pcarlini@suse.de>

	* config/locale/gnu/ctype_members.cc (do_is(mask, wchar_t)):
	Speed-up for the common case of mask == ctype_base::space;
	otherwise, exit the loop earlier if the mask is one of the
	elementary ones.


Index: ctype_members.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/locale/gnu/ctype_members.cc,v
retrieving revision 1.19
diff -p -r1.19 ctype_members.cc
*** ctype_members.cc	12 Aug 2004 09:46:39 -0000	1.19
--- ctype_members.cc	17 Jul 2005 18:12:23 -0000
*************** namespace std
*** 134,153 ****
    ctype<wchar_t>::
    do_is(mask __m, wchar_t __c) const
    { 
!     // Highest bitmask in ctype_base == 10, but extra in "C"
!     // library for blank.
      bool __ret = false;
!     const size_t __bitmasksize = 11; 
!     for (size_t __bitcur = 0; __bitcur <= __bitmasksize; ++__bitcur)
!       if (__m & _M_bit[__bitcur]
! 	  && __iswctype_l(__c, _M_wmask[__bitcur], _M_c_locale_ctype))
! 	{
! 	  __ret = true;
! 	  break;
! 	}
      return __ret;    
    }
!   
    const wchar_t* 
    ctype<wchar_t>::
    do_is(const wchar_t* __lo, const wchar_t* __hi, mask* __vec) const
--- 134,167 ----
    ctype<wchar_t>::
    do_is(mask __m, wchar_t __c) const
    { 
!     // The case of __m == ctype_base::space is particularly important,
!     // due to its use in many istream functions.  Therefore we deal with
!     // it first, exploiting the knowledge that on GNU systems _M_bit[5]
!     // is the mask corresponding to ctype_base::space.  NB: an encoding
!     // change would not affect correctness!
      bool __ret = false;
!     if (__m == _M_bit[5])
!       __ret = __iswctype_l(__c, _M_wmask[5], _M_c_locale_ctype);
!     else
!       {
! 	// Highest bitmask in ctype_base == 10, but extra in "C"
! 	// library for blank.
! 	const size_t __bitmasksize = 11;
! 	for (size_t __bitcur = 0; __bitcur <= __bitmasksize; ++__bitcur)
! 	  if (__m & _M_bit[__bitcur])
! 	    {
! 	      if (__iswctype_l(__c, _M_wmask[__bitcur], _M_c_locale_ctype))
! 		{
! 		  __ret = true;
! 		  break;
! 		}
! 	      else if (__m == _M_bit[__bitcur])
! 		break;
! 	    }
!       }
      return __ret;    
    }
! 
    const wchar_t* 
    ctype<wchar_t>::
    do_is(const wchar_t* __lo, const wchar_t* __hi, mask* __vec) const

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