This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

[Patch] Improve (more!) performance-wise __pad::_S_pad


Hi,

the below version, which only has the if-else tweaked, shaves
another quarter second:

baseline
--------
9.820u 0.040s 0:09.99 98.6%     0+0k 0+0io 193pf+0w

__pad_2 patch
-------------
8.550u 0.040s 0:08.63 99.5%     0+0k 0+0io 194pf+0w

Tested x86-linux. Will commit soon, if nobody objects...

Paolo.

///////////
2003-10-06  Paolo Carlini  <pcarlini@unitus.it>

	* include/bits/locale_facets.tcc (__pad<>::_S_pad):
	Improve performance-wise: avoid one traits::copy, avoid
	the __builtin_alloca, streamline.
diff -prN libstdc++-v3-1/include/bits/locale_facets.tcc libstdc++-v3/include/bits/locale_facets.tcc
*** libstdc++-v3-1/include/bits/locale_facets.tcc	Sun Oct  5 16:50:47 2003
--- libstdc++-v3/include/bits/locale_facets.tcc	Mon Oct  6 13:18:33 2003
*************** namespace std
*** 2207,2231 ****
  				   const streamsize __newlen, 
  				   const streamsize __oldlen, const bool __num)
      {
!       size_t __plen = static_cast<size_t>(__newlen - __oldlen);
!       _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) 
! 							     * __plen));
!       _Traits::assign(__pads, __plen, __fill); 
! 
!       _CharT* __beg;
!       _CharT* __end;
!       size_t __mod = 0;
!       size_t __beglen; //either __plen or __oldlen
!       ios_base::fmtflags __adjust = __io.flags() & ios_base::adjustfield;
  
        if (__adjust == ios_base::left)
  	{
! 	  // Padding last.
! 	  __beg = const_cast<_CharT*>(__olds);
! 	  __beglen = __oldlen;
! 	  __end = __pads;
  	}
!       else if (__adjust == ios_base::internal && __num)
  	{
  	  // Pad after the sign, if there is one.
  	  // Pad after 0[xX], if there is one.
--- 2207,2225 ----
  				   const streamsize __newlen, 
  				   const streamsize __oldlen, const bool __num)
      {
!       const size_t __plen = static_cast<size_t>(__newlen - __oldlen);
!       const ios_base::fmtflags __adjust = __io.flags() & ios_base::adjustfield;
  
+       // Padding last.
        if (__adjust == ios_base::left)
  	{
! 	  _Traits::copy(__news, const_cast<_CharT*>(__olds), __oldlen);
! 	  _Traits::assign(__news + __oldlen, __plen, __fill);
! 	  return;
  	}
! 
!       size_t __mod = 0;
!       if (__adjust == ios_base::internal && __num)
  	{
  	  // Pad after the sign, if there is one.
  	  // Pad after 0[xX], if there is one.
*************** namespace std
*** 2254,2273 ****
  	      ++__news;
  	    }
  	  // else Padding first.
- 	  
- 	  __beg = __pads;
- 	  __beglen = __plen;
- 	  __end = const_cast<_CharT*>(__olds + __mod);
- 	}
-       else
- 	{
- 	  // Padding first.
- 	  __beg = __pads;
- 	  __beglen = __plen;
- 	  __end = const_cast<_CharT*>(__olds);
  	}
!       _Traits::copy(__news, __beg, __beglen);
!       _Traits::copy(__news + __beglen, __end, __newlen - __beglen - __mod);
      }
  
    template<typename _CharT>
--- 2248,2257 ----
  	      ++__news;
  	    }
  	  // else Padding first.
  	}
!       _Traits::assign(__news, __plen, __fill);
!       _Traits::copy(__news + __plen, const_cast<_CharT*>(__olds + __mod),
! 		    __oldlen - __mod);
      }
  
    template<typename _CharT>

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