diff options
| author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-10-10 17:10:47 +0000 |
|---|---|---|
| committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-10-10 17:10:47 +0000 |
| commit | d292eeeeb230a3a97fb900b7b357ced3769e8fcf (patch) | |
| tree | 809614ad8ac2d034a844a7aa54550d9e0f67a2e0 | |
| parent | dbc978761da4235401f08a9f9f1c22531a94c914 (diff) | |
| download | ppe42-gcc-d292eeeeb230a3a97fb900b7b357ced3769e8fcf.tar.gz ppe42-gcc-d292eeeeb230a3a97fb900b7b357ced3769e8fcf.zip | |
2003-10-10 Paolo Carlini <pcarlini@unitus.it>
* include/bits/ostream.tcc (operator<<(basic_ostream&, _CharT))
Avoid unnecessarily calling __builtin_alloca and dealing
explicitly with width() smaller than zero.
(operator<<(basic_ostream&, char), operator<<(basic_ostream&,
const _CharT*), operator<<(basic_ostream<_CharT, _Traits>&,
const char*), operator<<(basic_ostream<char, _Traits>&,
const char*), operator<<(basic_ostream, const basic_string&)):
Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@72302 138bc75d-0d04-0410-961f-82ee72b054a4
| -rw-r--r-- | libstdc++-v3/ChangeLog | 11 | ||||
| -rw-r--r-- | libstdc++-v3/include/bits/ostream.tcc | 63 |
2 files changed, 44 insertions, 30 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 08950d9f9f7..865d9be2a6f 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,14 @@ +2003-10-10 Paolo Carlini <pcarlini@unitus.it> + + * include/bits/ostream.tcc (operator<<(basic_ostream&, _CharT)) + Avoid unnecessarily calling __builtin_alloca and dealing + explicitly with width() smaller than zero. + (operator<<(basic_ostream&, char), operator<<(basic_ostream&, + const _CharT*), operator<<(basic_ostream<_CharT, _Traits>&, + const char*), operator<<(basic_ostream<char, _Traits>&, + const char*), operator<<(basic_ostream, const basic_string&)): + Likewise. + 2003-10-09 Benjamin Kosnik <bkoz@redhat.com> * config/linker-map.gnu: Make more *_type_info bits visible. diff --git a/libstdc++-v3/include/bits/ostream.tcc b/libstdc++-v3/include/bits/ostream.tcc index 401b58ff80f..fee2f2757df 100644 --- a/libstdc++-v3/include/bits/ostream.tcc +++ b/libstdc++-v3/include/bits/ostream.tcc @@ -471,17 +471,18 @@ namespace std { try { - const streamsize __w = __out.width() > 0 ? __out.width() : 0; - _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * (__w + 1))); - __pads[0] = __c; + const streamsize __w = __out.width(); streamsize __len = 1; + _CharT* __cs = &__c; if (__w > __len) { - __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __pads, + __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) + * __w)); + __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs, &__c, __w, __len, false); __len = __w; } - __out._M_write(__pads, __len); + __out._M_write(__cs, __len); __out.width(0); } catch(...) @@ -507,17 +508,17 @@ namespace std { try { - const streamsize __w = __out.width() > 0 ? __out.width() : 0; - char* __pads = static_cast<char*>(__builtin_alloca(__w + 1)); - __pads[0] = __c; + const streamsize __w = __out.width(); streamsize __len = 1; + char* __cs = &__c; if (__w > __len) { - __pad<char, _Traits>::_S_pad(__out, __out.fill(), __pads, + __cs = static_cast<char*>(__builtin_alloca(__w)); + __pad<char, _Traits>::_S_pad(__out, __out.fill(), __cs, &__c, __w, __len, false); __len = __w; } - __out._M_write(__pads, __len); + __out._M_write(__cs, __len); __out.width(0); } catch(...) @@ -542,14 +543,15 @@ namespace std { try { - const streamsize __w = __out.width() > 0 ? __out.width() : 0; - _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w)); + const streamsize __w = __out.width(); streamsize __len = static_cast<streamsize>(_Traits::length(__s)); if (__w > __len) { - __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __pads, + _CharT* __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) + * __w)); + __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs, __s, __w, __len, false); - __s = __pads; + __s = __cs; __len = __w; } __out._M_write(__s, __len); @@ -583,22 +585,23 @@ namespace std if (__cerb && __s) { size_t __clen = __traits_type::length(__s); - _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * (__clen + 1))); + _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) + * __clen)); for (size_t __i = 0; __i < __clen; ++__i) __ws[__i] = __out.widen(__s[__i]); _CharT* __str = __ws; try { + const streamsize __w = __out.width(); streamsize __len = static_cast<streamsize>(__clen); - const streamsize __w = __out.width() > 0 ? __out.width() : 0; - _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w)); - if (__w > __len) { - __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __pads, + _CharT* __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) + * __w)); + __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs, __ws, __w, __len, false); - __str = __pads; + __str = __cs; __len = __w; } __out._M_write(__str, __len); @@ -629,15 +632,14 @@ namespace std { try { - const streamsize __w = __out.width() > 0 ? __out.width() : 0; - char* __pads = static_cast<char*>(__builtin_alloca(__w)); + const streamsize __w = __out.width(); streamsize __len = static_cast<streamsize>(_Traits::length(__s)); - if (__w > __len) { - __pad<char, _Traits>::_S_pad(__out, __out.fill(), __pads, + char* __cs = static_cast<char*>(__builtin_alloca(__w)); + __pad<char, _Traits>::_S_pad(__out, __out.fill(), __cs, __s, __w, __len, false); - __s = __pads; + __s = __cs; __len = __w; } __out._M_write(__s, __len); @@ -667,18 +669,19 @@ namespace std typename __ostream_type::sentry __cerb(__out); if (__cerb) { - const _CharT* __s = __str.data(); - const streamsize __w = __out.width() > 0 ? __out.width() : 0; - _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w)); + const streamsize __w = __out.width(); streamsize __len = static_cast<streamsize>(__str.size()); + const _CharT* __s = __str.data(); #ifdef _GLIBCXX_RESOLVE_LIB_DEFECTS // 25. String operator<< uses width() value wrong #endif if (__w > __len) { - __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __pads, __s, + _CharT* __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) + * __w)); + __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs, __s, __w, __len, false); - __s = __pads; + __s = __cs; __len = __w; } __out._M_write(__s, __len); |

