[libcxx] r196951 - Refactored a bunch of duplicated code in <ostream>. Made a new routine called __put_character_sequence, and made nine places call it.
Marshall Clow
mclow.lists at gmail.com
Tue Dec 10 11:25:49 PST 2013
Author: marshall
Date: Tue Dec 10 13:25:49 2013
New Revision: 196951
URL: http://llvm.org/viewvc/llvm-project?rev=196951&view=rev
Log:
Refactored a bunch of duplicated code in <ostream>. Made a new routine called __put_character_sequence, and made nine places call it.
Modified:
libcxx/trunk/include/ostream
Modified: libcxx/trunk/include/ostream
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/ostream?rev=196951&r1=196950&r2=196951&view=diff
==============================================================================
--- libcxx/trunk/include/ostream (original)
+++ libcxx/trunk/include/ostream Tue Dec 10 13:25:49 2013
@@ -729,7 +729,8 @@ basic_ostream<_CharT, _Traits>::operator
template<class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
+__put_character_sequence(basic_ostream<_CharT, _Traits>& __os,
+ const _CharT* __str, size_t __len)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
@@ -740,11 +741,11 @@ operator<<(basic_ostream<_CharT, _Traits
{
typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
if (__pad_and_output(_Ip(__os),
- &__c,
+ __str,
(__os.flags() & ios_base::adjustfield) == ios_base::left ?
- &__c + 1 :
- &__c,
- &__c + 1,
+ __str + __len :
+ __str,
+ __str + __len,
__os,
__os.fill()).failed())
__os.setstate(ios_base::badbit | ios_base::failbit);
@@ -759,6 +760,14 @@ operator<<(basic_ostream<_CharT, _Traits
return __os;
}
+
+template<class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
+{
+ return _VSTD::__put_character_sequence(__os, &__c, 1);
+}
+
template<class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
@@ -796,129 +805,28 @@ template<class _Traits>
basic_ostream<char, _Traits>&
operator<<(basic_ostream<char, _Traits>& __os, char __c)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
-#endif // _LIBCPP_NO_EXCEPTIONS
- typename basic_ostream<char, _Traits>::sentry __s(__os);
- if (__s)
- {
- typedef ostreambuf_iterator<char, _Traits> _Ip;
- if (__pad_and_output(_Ip(__os),
- &__c,
- (__os.flags() & ios_base::adjustfield) == ios_base::left ?
- &__c + 1 :
- &__c,
- &__c + 1,
- __os,
- __os.fill()).failed())
- __os.setstate(ios_base::badbit | ios_base::failbit);
- }
-#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- __os.__set_badbit_and_consider_rethrow();
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
- return __os;
+ return _VSTD::__put_character_sequence(__os, &__c, 1);
}
template<class _Traits>
basic_ostream<char, _Traits>&
operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
-#endif // _LIBCPP_NO_EXCEPTIONS
- typename basic_ostream<char, _Traits>::sentry __s(__os);
- if (__s)
- {
- typedef ostreambuf_iterator<char, _Traits> _Ip;
- if (__pad_and_output(_Ip(__os),
- (char*)&__c,
- (__os.flags() & ios_base::adjustfield) == ios_base::left ?
- (char*)&__c + 1 :
- (char*)&__c,
- (char*)&__c + 1,
- __os,
- __os.fill()).failed())
- __os.setstate(ios_base::badbit | ios_base::failbit);
- }
-#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- __os.__set_badbit_and_consider_rethrow();
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
- return __os;
+ return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
}
template<class _Traits>
basic_ostream<char, _Traits>&
operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
-#endif // _LIBCPP_NO_EXCEPTIONS
- typename basic_ostream<char, _Traits>::sentry __s(__os);
- if (__s)
- {
- typedef ostreambuf_iterator<char, _Traits> _Ip;
- if (__pad_and_output(_Ip(__os),
- (char*)&__c,
- (__os.flags() & ios_base::adjustfield) == ios_base::left ?
- (char*)&__c + 1 :
- (char*)&__c,
- (char*)&__c + 1,
- __os,
- __os.fill()).failed())
- __os.setstate(ios_base::badbit | ios_base::failbit);
- }
-#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- __os.__set_badbit_and_consider_rethrow();
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
- return __os;
+ return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
}
template<class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
-#endif // _LIBCPP_NO_EXCEPTIONS
- typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
- if (__s)
- {
- typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
- size_t __len = _Traits::length(__str);
- if (__pad_and_output(_Ip(__os),
- __str,
- (__os.flags() & ios_base::adjustfield) == ios_base::left ?
- __str + __len :
- __str,
- __str + __len,
- __os,
- __os.fill()).failed())
- __os.setstate(ios_base::badbit | ios_base::failbit);
- }
-#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- __os.__set_badbit_and_consider_rethrow();
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
- return __os;
+ return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
}
template<class _CharT, class _Traits>
@@ -971,99 +879,23 @@ template<class _Traits>
basic_ostream<char, _Traits>&
operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
-#endif // _LIBCPP_NO_EXCEPTIONS
- typename basic_ostream<char, _Traits>::sentry __s(__os);
- if (__s)
- {
- typedef ostreambuf_iterator<char, _Traits> _Ip;
- size_t __len = _Traits::length(__str);
- if (__pad_and_output(_Ip(__os),
- __str,
- (__os.flags() & ios_base::adjustfield) == ios_base::left ?
- __str + __len :
- __str,
- __str + __len,
- __os,
- __os.fill()).failed())
- __os.setstate(ios_base::badbit | ios_base::failbit);
- }
-#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- __os.__set_badbit_and_consider_rethrow();
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
- return __os;
+ return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
}
template<class _Traits>
basic_ostream<char, _Traits>&
operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
-#endif // _LIBCPP_NO_EXCEPTIONS
- typename basic_ostream<char, _Traits>::sentry __s(__os);
- if (__s)
- {
- typedef ostreambuf_iterator<char, _Traits> _Ip;
- size_t __len = _Traits::length((const char*)__str);
- if (__pad_and_output(_Ip(__os),
- (const char*)__str,
- (__os.flags() & ios_base::adjustfield) == ios_base::left ?
- (const char*)__str + __len :
- (const char*)__str,
- (const char*)__str + __len,
- __os,
- __os.fill()).failed())
- __os.setstate(ios_base::badbit | ios_base::failbit);
- }
-#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- __os.__set_badbit_and_consider_rethrow();
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
- return __os;
+ const char *__s = (const char *) __str;
+ return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
}
template<class _Traits>
basic_ostream<char, _Traits>&
operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
-#endif // _LIBCPP_NO_EXCEPTIONS
- typename basic_ostream<char, _Traits>::sentry __s(__os);
- if (__s)
- {
- typedef ostreambuf_iterator<char, _Traits> _Ip;
- size_t __len = _Traits::length((const char*)__str);
- if (__pad_and_output(_Ip(__os),
- (const char*)__str,
- (__os.flags() & ios_base::adjustfield) == ios_base::left ?
- (const char*)__str + __len :
- (const char*)__str,
- (const char*)__str + __len,
- __os,
- __os.fill()).failed())
- __os.setstate(ios_base::badbit | ios_base::failbit);
- }
-#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- __os.__set_badbit_and_consider_rethrow();
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
- return __os;
+ const char *__s = (const char *) __str;
+ return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
}
template <class _CharT, class _Traits>
@@ -1233,33 +1065,7 @@ basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os,
const basic_string<_CharT, _Traits, _Allocator>& __str)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
-#endif // _LIBCPP_NO_EXCEPTIONS
- typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
- if (__s)
- {
- typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
- size_t __len = __str.size();
- if (__pad_and_output(_Ip(__os),
- __str.data(),
- (__os.flags() & ios_base::adjustfield) == ios_base::left ?
- __str.data() + __len :
- __str.data(),
- __str.data() + __len,
- __os,
- __os.fill()).failed())
- __os.setstate(ios_base::badbit | ios_base::failbit);
- }
-#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- __os.__set_badbit_and_consider_rethrow();
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
- return __os;
+ return _VSTD::__put_character_sequence(__os, __str.data(), __str.size());
}
template <class _CharT, class _Traits>
More information about the cfe-commits
mailing list