diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c52e42dc808..644f3d016ea 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2000-07-15 Gabriel Dos Reis + + * bits/valarray_array.h (__valarray_get_storage): New function. + (_Array<>::Array): Use it. + * bits/std_valarray.h (valarray<>::valarray): Likewise. + (valarray<>::resize): Likewise. Tweak. + * src/valarray-inst.cc (__valarray_product): Tweak. + 2000-07-11 Phil Edwards * docs: Update sourceware->sources in every HTML file. Minor updates. diff --git a/libstdc++-v3/bits/std_valarray.h b/libstdc++-v3/bits/std_valarray.h index 63daf9fd6bd..fa43c6dca0c 100644 --- a/libstdc++-v3/bits/std_valarray.h +++ b/libstdc++-v3/bits/std_valarray.h @@ -259,78 +259,61 @@ namespace std { template inline valarray<_Tp>::valarray (size_t __n) - : _M_size(__n), - _M_data(static_cast<_Tp*__restrict__> - (__valarray_get_memory(__n * sizeof (_Tp)))) + : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n)) { __valarray_default_construct(_M_data, _M_data + __n); } template inline valarray<_Tp>::valarray (const _Tp& __t, size_t __n) - : _M_size(__n), - _M_data(static_cast<_Tp*__restrict__> - (__valarray_get_memory(__n * sizeof (_Tp)))) + : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n)) { __valarray_fill_construct (_M_data, _M_data + __n, __t); } template inline valarray<_Tp>::valarray (const _Tp* __restrict__ __p, size_t __n) - : _M_size(__n), - _M_data(static_cast<_Tp*__restrict__> - (__valarray_get_memory(__n * sizeof (_Tp)))) + : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n)) { __valarray_copy_construct (__p, __p + __n, _M_data); } template inline valarray<_Tp>::valarray (const valarray<_Tp>& __v) - : _M_size(__v._M_size), - _M_data(static_cast<_Tp*__restrict__> - (__valarray_get_memory(__v._M_size * sizeof (_Tp)))) + : _M_size(__v._M_size), _M_data(__valarray_get_storage<_Tp>(__v._M_size)) { __valarray_copy_construct (__v._M_data, __v._M_data + _M_size, _M_data); } template inline valarray<_Tp>::valarray (const slice_array<_Tp>& __sa) - : _M_size(__sa._M_sz), - _M_data(static_cast<_Tp*__restrict__> - (__valarray_get_memory(__sa._M_sz * sizeof (_Tp)))) + : _M_size(__sa._M_sz), _M_data(__valarray_get_storage<_Tp>(__sa._M_sz)) { - __valarray_copy_construct - (__sa._M_array, __sa._M_sz, __sa._M_stride, _Array<_Tp>(_M_data)); + __valarray_copy_construct + (__sa._M_array, __sa._M_sz, __sa._M_stride, _Array<_Tp>(_M_data)); } template inline valarray<_Tp>::valarray (const gslice_array<_Tp>& __ga) - : _M_size(__ga._M_index.size()), - _M_data(static_cast<_Tp*__restrict__> - (__valarray_get_memory(_M_size * sizeof (_Tp)))) + : _M_size(__ga._M_index.size()), + _M_data(__valarray_get_storage<_Tp>(_M_size)) { - __valarray_copy_construct - (__ga._M_array, _Array(__ga._M_index), - _Array<_Tp>(_M_data), _M_size); + __valarray_copy_construct + (__ga._M_array, _Array(__ga._M_index), + _Array<_Tp>(_M_data), _M_size); } template inline valarray<_Tp>::valarray (const mask_array<_Tp>& __ma) - : _M_size(__ma._M_sz), - _M_data(static_cast<_Tp*__restrict__> - (__valarray_get_memory(__ma._M_sz * sizeof (_Tp)))) + : _M_size(__ma._M_sz), _M_data(__valarray_get_storage<_Tp>(__ma._M_sz)) { - __valarray_copy_construct - (__ma._M_array, __ma._M_mask, _Array<_Tp>(_M_data), _M_size); + __valarray_copy_construct + (__ma._M_array, __ma._M_mask, _Array<_Tp>(_M_data), _M_size); } template inline valarray<_Tp>::valarray (const indirect_array<_Tp>& __ia) - : _M_size(__ia._M_sz), - _M_data(static_cast<_Tp*__restrict__> - (__valarray_get_memory(__ia._M_sz * sizeof (_Tp)))) + : _M_size(__ia._M_sz), _M_data(__valarray_get_storage<_Tp>(__ia._M_sz)) { - __valarray_copy_construct - (__ia._M_array, __ia._M_index, _Array<_Tp>(_M_data), _M_size); + __valarray_copy_construct + (__ia._M_array, __ia._M_index, _Array<_Tp>(_M_data), _M_size); } template template inline valarray<_Tp>::valarray (const _Expr<_Dom, _Tp>& __e) - : _M_size(__e.size ()), - _M_data(static_cast<_Tp*__restrict__> - (__valarray_copy_construct(_M_size * sizeof (_Tp)))) + : _M_size(__e.size ()), _M_data(__valarray_get_storage<_Tp>(_M_size)) { __valarray_copy_construct (__e, _M_size, _Array<_Tp>(_M_data)); } template @@ -536,20 +519,17 @@ namespace std { inline void valarray<_Tp>::resize (size_t __n, _Tp __c) { - if (_M_size != __n) { - __valarray_destroy_elements(_M_data, _M_data + _M_size); - __valarray_release_memory(_M_data); - _M_size = __n; - _M_data = static_cast<_Tp*__restrict__> - (__valarray_get_memory(__n * sizeof (_Tp))); - __valarray_fill_construct(_M_data, _M_data + __n, __c); - } - else { - // this is so to make valarray > work - // even though it is not required by the standard. - __valarray_destroy_elements(_M_data, _M_data + _M_size); - __valarray_fill_construct(_M_data, _M_data + _M_size, __c); + // This complication is so to make valarray > work + // even though it is not required by the standard. Nobody should + // be saying valarray > anyway. See the specs. + __valarray_destroy_elements(_M_data, _M_data + _M_size); + if (_M_size != __n) + { + __valarray_release_memory(_M_data); + _M_size = __n; + _M_data = __valarray_get_storage<_Tp>(__n); } + __valarray_fill_construct(_M_data, _M_data + __n, __c); } template diff --git a/libstdc++-v3/bits/valarray_array.h b/libstdc++-v3/bits/valarray_array.h index c2f40c39127..5a792d29c82 100644 --- a/libstdc++-v3/bits/valarray_array.h +++ b/libstdc++-v3/bits/valarray_array.h @@ -50,6 +50,14 @@ namespace std __valarray_get_memory(size_t __n) { return operator new(__n); } + template + inline _Tp*__restrict__ + __valarray_get_storage(size_t __n) + { + return static_cast<_Tp*__restrict__> + (__valarray_get_memory(__n * sizeof(_Tp))); + } + // Return memory to the system inline void __valarray_release_memory(void* __p) @@ -352,7 +360,7 @@ namespace std template inline _Array<_Tp>::_Array (size_t __n) - : _M_data(__valarray_get_memory(__n * sizeof (_Tp))) + : _M_data(__valarray_get_storage<_Tp>(__n)) { __valarray_default_construct(_M_data, _M_data + __n); } template @@ -366,7 +374,7 @@ namespace std template inline _Array<_Tp>::_Array (const _Tp* __restrict__ __b, size_t __s) - : _M_data(__valarray_get_memory(__s * sizeof (_Tp))) + : _M_data(__valarray_get_storage<_Tp>(__s)) { __valarray_copy_construct(__b, __s, _M_data); } template diff --git a/libstdc++-v3/src/valarray-inst.cc b/libstdc++-v3/src/valarray-inst.cc index ce0f86feeec..94d1188e523 100644 --- a/libstdc++-v3/src/valarray-inst.cc +++ b/libstdc++-v3/src/valarray-inst.cc @@ -22,14 +22,13 @@ namespace std inline size_t __valarray_product(const valarray& __a) { + typedef const size_t* __restrict__ _Tp; + const size_t __n = __a.size(); // XXX: This ugly cast is necessary because // valarray::operator[]() const return a VALUE! // Try to get the committee to correct that gross error. - typedef const size_t* __restrict__ _Tp; - size_t __n = __a.size() - 1; valarray& __t = const_cast&>(__a); - return __valarray_product(static_cast<_Tp>(&__t[0]), - static_cast<_Tp>(&__t[__n])); + return __valarray_product(&__t[0], &__t[0] + __n); } void __gslice_to_index(size_t __o, const valarray& __l,