Mercurial > hg > octave-nkf
diff liboctave/Array.cc @ 8524:937921654627
clean up Array and DiagArray2
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 15 Jan 2009 07:22:24 +0100 |
parents | ad3afaaa19c1 |
children | 17e0ad741fac |
line wrap: on
line diff
--- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -46,6 +46,26 @@ // all the derived classes. template <class T> +void +Array<T>::make_unique (void) +{ + if (rep->count > 1) + { + --rep->count; + rep = new ArrayRep (slice_data, slice_len, true); + slice_data = rep->data; + } + else if (slice_len != rep->len) + { + // Possibly economize here. + ArrayRep *new_rep = new ArrayRep (slice_data, slice_len, true); + delete rep; + rep = new_rep; + slice_data = rep->data; + } +} + +template <class T> Array<T>::Array (const Array<T>& a, const dim_vector& dv) : rep (a.rep), dimensions (dv), slice_data (a.slice_data), slice_len (a.slice_len) @@ -85,6 +105,20 @@ } template <class T> +void +Array<T>::fill (const T& val) +{ + if (rep->count > 1) + { + --rep->count; + rep = new ArrayRep (length (), val); + slice_data = rep->data; + } + else + std::fill (slice_data, slice_data + slice_len, val); +} + +template <class T> Array<T> Array<T>::squeeze (void) const { @@ -131,13 +165,7 @@ } } - // FIXME -- it would be better if we did not have to do - // this, so we could share the data while still having different - // dimension vectors. - - retval.make_unique (); - - retval.dimensions = new_dimensions; + retval = Array<T> (*this, new_dimensions); } return retval;