From patchwork Thu Jun 17 08:41:02 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 55986 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id EFF9E100875 for ; Thu, 17 Jun 2010 18:41:29 +1000 (EST) Received: (qmail 27258 invoked by alias); 17 Jun 2010 08:41:25 -0000 Received: (qmail 27219 invoked by uid 22791); 17 Jun 2010 08:41:16 -0000 X-SWARE-Spam-Status: No, hits=-0.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from vsmtp14.tin.it (HELO vsmtp14.tin.it) (212.216.176.118) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 17 Jun 2010 08:41:06 +0000 Received: from [192.168.0.4] (79.47.211.113) by vsmtp14.tin.it (8.5.113) id 4BCE303705978642; Thu, 17 Jun 2010 10:41:03 +0200 Message-ID: <4C19DF9E.4040506@oracle.com> Date: Thu, 17 Jun 2010 10:41:02 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100317 SUSE/3.0.4-1.1.1 Thunderbird/3.0.4 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ , Jason Merrill Subject: [v3] Add __uninitialized_default*; use __is_trivial instead of __is_pod in most places X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, Some infrastructure for forthcoming C++0x work + finally got around to use __is_trivial instead of the more restrictive __is_pod in many places. About the latter in particular, I'm also adding in CC Jason - implemented __is_trivial and briefly discussed with him the rather straightforward plan of replacing most dispatches in the library based on POD-ness to trivial-ness. Tested x86_64-linux, committed to mainline. Paolo. //////////////////// 2010-06-17 Paolo Carlini * include/bits/stl_uninitialized.h (__uninitialized_default, __uninitialized_default_n, __uninitialized_default_a, __uninitialized_default_n_a): Add. * include/bits/stl_uninitialized.h (uninitialized_copy, uninitialized_fill, uninitialized_fill_n): Use __is_trivial instead of __is_pod. * include/bits/valarray_array.h: Likewise. * include/bits/stl_algobase.h (__copy_move_backward_a, __copy_move_a): Likewise. Index: include/bits/stl_algobase.h =================================================================== --- include/bits/stl_algobase.h (revision 160877) +++ include/bits/stl_algobase.h (working copy) @@ -394,7 +394,7 @@ typedef typename iterator_traits<_II>::value_type _ValueTypeI; typedef typename iterator_traits<_OI>::value_type _ValueTypeO; typedef typename iterator_traits<_II>::iterator_category _Category; - const bool __simple = (__is_pod(_ValueTypeI) + const bool __simple = (__is_trivial(_ValueTypeI) && __is_pointer<_II>::__value && __is_pointer<_OI>::__value && __are_same<_ValueTypeI, _ValueTypeO>::__value); @@ -589,7 +589,7 @@ typedef typename iterator_traits<_BI1>::value_type _ValueType1; typedef typename iterator_traits<_BI2>::value_type _ValueType2; typedef typename iterator_traits<_BI1>::iterator_category _Category; - const bool __simple = (__is_pod(_ValueType1) + const bool __simple = (__is_trivial(_ValueType1) && __is_pointer<_BI1>::__value && __is_pointer<_BI2>::__value && __are_same<_ValueType1, _ValueType2>::__value); Index: include/bits/stl_uninitialized.h =================================================================== --- include/bits/stl_uninitialized.h (revision 160877) +++ include/bits/stl_uninitialized.h (working copy) @@ -60,13 +60,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std) - template + template struct __uninitialized_copy { template static _ForwardIterator - uninitialized_copy(_InputIterator __first, _InputIterator __last, - _ForwardIterator __result) + __uninit_copy(_InputIterator __first, _InputIterator __last, + _ForwardIterator __result) { _ForwardIterator __cur = __result; __try @@ -88,8 +88,8 @@ { template static _ForwardIterator - uninitialized_copy(_InputIterator __first, _InputIterator __last, - _ForwardIterator __result) + __uninit_copy(_InputIterator __first, _InputIterator __last, + _ForwardIterator __result) { return std::copy(__first, __last, __result); } }; @@ -112,19 +112,19 @@ typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType2; - return std::__uninitialized_copy<(__is_pod(_ValueType1) - && __is_pod(_ValueType2))>:: - uninitialized_copy(__first, __last, __result); + return std::__uninitialized_copy<(__is_trivial(_ValueType1) + && __is_trivial(_ValueType2))>:: + __uninit_copy(__first, __last, __result); } - template + template struct __uninitialized_fill { template static void - uninitialized_fill(_ForwardIterator __first, - _ForwardIterator __last, const _Tp& __x) + __uninit_fill(_ForwardIterator __first, _ForwardIterator __last, + const _Tp& __x) { _ForwardIterator __cur = __first; __try @@ -145,8 +145,8 @@ { template static void - uninitialized_fill(_ForwardIterator __first, - _ForwardIterator __last, const _Tp& __x) + __uninit_fill(_ForwardIterator __first, _ForwardIterator __last, + const _Tp& __x) { std::fill(__first, __last, __x); } }; @@ -167,18 +167,18 @@ typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; - std::__uninitialized_fill<__is_pod(_ValueType)>:: - uninitialized_fill(__first, __last, __x); + std::__uninitialized_fill<__is_trivial(_ValueType)>:: + __uninit_fill(__first, __last, __x); } - template + template struct __uninitialized_fill_n { template static void - uninitialized_fill_n(_ForwardIterator __first, _Size __n, - const _Tp& __x) + __uninit_fill_n(_ForwardIterator __first, _Size __n, + const _Tp& __x) { _ForwardIterator __cur = __first; __try @@ -199,8 +199,8 @@ { template static void - uninitialized_fill_n(_ForwardIterator __first, _Size __n, - const _Tp& __x) + __uninit_fill_n(_ForwardIterator __first, _Size __n, + const _Tp& __x) { std::fill_n(__first, __n, __x); } }; @@ -220,8 +220,8 @@ typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; - std::__uninitialized_fill_n<__is_pod(_ValueType)>:: - uninitialized_fill_n(__first, __n, __x); + std::__uninitialized_fill_n<__is_trivial(_ValueType)>:: + __uninit_fill_n(__first, __n, __x); } // Extensions: versions of uninitialized_copy, uninitialized_fill, @@ -427,6 +427,166 @@ } #ifdef __GXX_EXPERIMENTAL_CXX0X__ + // Extensions: __uninitialized_default, __uninitialized_default_n, + // __uninitialized_default_a, __uninitialized_default_n_a. + + template + struct __uninitialized_default_1 + { + template + static void + __uninit_default(_ForwardIterator __first, _ForwardIterator __last) + { + _ForwardIterator __cur = __first; + __try + { + for (; __cur != __last; ++__cur) + std::_Construct(std::__addressof(*__cur)); + } + __catch(...) + { + std::_Destroy(__first, __cur); + __throw_exception_again; + } + } + }; + + template<> + struct __uninitialized_default_1 + { + template + static void + __uninit_default(_ForwardIterator __first, _ForwardIterator __last) + { + typedef typename iterator_traits<_ForwardIterator>::value_type + _ValueType; + + std::fill(__first, __last, _ValueType()); + } + }; + + template + struct __uninitialized_default_n_1 + { + template + static void + __uninit_default_n(_ForwardIterator __first, _Size __n) + { + _ForwardIterator __cur = __first; + __try + { + for (; __n > 0; --__n, ++__cur) + std::_Construct(std::__addressof(*__cur)); + } + __catch(...) + { + std::_Destroy(__first, __cur); + __throw_exception_again; + } + } + }; + + template<> + struct __uninitialized_default_n_1 + { + template + static void + __uninit_default_n(_ForwardIterator __first, _Size __n) + { + typedef typename iterator_traits<_ForwardIterator>::value_type + _ValueType; + + std::fill_n(__first, __n, _ValueType()); + } + }; + + // __uninitialized_default + // Fills [first, last) with std::distance(first, last) default + // constructed value_types(s). + template + inline void + __uninitialized_default(_ForwardIterator __first, + _ForwardIterator __last) + { + typedef typename iterator_traits<_ForwardIterator>::value_type + _ValueType; + + std::__uninitialized_default_1<__is_trivial(_ValueType)>:: + __uninit_default(__first, __last); + } + + // __uninitialized_default_n + // Fills [first, first + n) with n default constructed value_type(s). + template + inline void + __uninitialized_default_n(_ForwardIterator __first, _Size __n) + { + typedef typename iterator_traits<_ForwardIterator>::value_type + _ValueType; + + std::__uninitialized_default_n_1<__is_trivial(_ValueType)>:: + __uninit_default_n(__first, __n); + } + + + // __uninitialized_default_a + // Fills [first, last) with std::distance(first, last) default + // constructed value_types(s), constructed with the allocator alloc. + template + void + __uninitialized_default_a(_ForwardIterator __first, + _ForwardIterator __last, + _Allocator& __alloc) + { + _ForwardIterator __cur = __first; + __try + { + for (; __cur != __last; ++__cur) + __alloc.construct(std::__addressof(*__cur)); + } + __catch(...) + { + std::_Destroy(__first, __cur, __alloc); + __throw_exception_again; + } + } + + template + inline void + __uninitialized_default_a(_ForwardIterator __first, + _ForwardIterator __last, + allocator<_Tp>&) + { std::__uninitialized_default(__first, __last); } + + + // __uninitialized_default_n_a + // Fills [first, first + n) with n default constructed value_types(s), + // constructed with the allocator alloc. + template + void + __uninitialized_default_n_a(_ForwardIterator __first, _Size __n, + _Allocator& __alloc) + { + _ForwardIterator __cur = __first; + __try + { + for (; __n > 0; --__n, ++__cur) + __alloc.construct(std::__addressof(*__cur)); + } + __catch(...) + { + std::_Destroy(__first, __cur, __alloc); + __throw_exception_again; + } + } + + template + inline void + __uninitialized_default_n_a(_ForwardIterator __first, _Size __n, + allocator<_Tp>&) + { std::__uninitialized_default_n(__first, __n); } + + template _ForwardIterator Index: include/bits/valarray_array.h =================================================================== --- include/bits/valarray_array.h (revision 160877) +++ include/bits/valarray_array.h (working copy) @@ -1,7 +1,7 @@ // The template and inlines for the -*- C++ -*- internal _Array helper class. // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, -// 2006, 2007, 2008, 2009 +// 2006, 2007, 2008, 2009, 2010 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -127,7 +127,7 @@ inline void __valarray_fill_construct(_Tp* __b, _Tp* __e, const _Tp __t) { - _Array_init_ctor<_Tp, __is_pod(_Tp)>::_S_do_it(__b, __e, __t); + _Array_init_ctor<_Tp, __is_trivial(_Tp)>::_S_do_it(__b, __e, __t); } // @@ -160,7 +160,7 @@ __valarray_copy_construct(const _Tp* __b, const _Tp* __e, _Tp* __restrict__ __o) { - _Array_copy_ctor<_Tp, __is_pod(_Tp)>::_S_do_it(__b, __e, __o); + _Array_copy_ctor<_Tp, __is_trivial(_Tp)>::_S_do_it(__b, __e, __o); } // copy-construct raw array [__o, *) from strided array __a[<__n : __s>] @@ -169,7 +169,7 @@ __valarray_copy_construct (const _Tp* __restrict__ __a, size_t __n, size_t __s, _Tp* __restrict__ __o) { - if (__is_pod(_Tp)) + if (__is_trivial(_Tp)) while (__n--) { *__o++ = *__a; @@ -190,7 +190,7 @@ const size_t* __restrict__ __i, _Tp* __restrict__ __o, size_t __n) { - if (__is_pod(_Tp)) + if (__is_trivial(_Tp)) while (__n--) *__o++ = __a[*__i++]; else @@ -203,7 +203,7 @@ inline void __valarray_destroy_elements(_Tp* __b, _Tp* __e) { - if (!__is_pod(_Tp)) + if (!__is_trivial(_Tp)) while (__b != __e) { __b->~_Tp(); @@ -267,7 +267,7 @@ __valarray_copy(const _Tp* __restrict__ __a, size_t __n, _Tp* __restrict__ __b) { - _Array_copier<_Tp, __is_pod(_Tp)>::_S_do_it(__a, __n, __b); + _Array_copier<_Tp, __is_trivial(_Tp)>::_S_do_it(__a, __n, __b); } // Copy strided array __a[<__n : __s>] in plain __b[<__n>]