This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] Improve performance-wise __pad::_S_pad
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 06 Oct 2003 21:48:22 +0200
- Subject: [v3] Improve performance-wise __pad::_S_pad
Hi,
tested x86-linux, committed.
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 18:29:58 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>