Mercurial > hg > octave-nkf
changeset 13995:8a566473361e
use static storage for Sparse nil rep instead of allocating it with new
* Sparse.h (Sparse<T>::SparseRep::nil_rep): Use static object for nil
rep instead of allocating it with new.
(Sparse<T>::Sparse (void)): Increment count here, not in
Sparse<T>::SparseRep::nil_rep.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 05 Dec 2011 00:30:54 -0500 |
parents | 99f039289e95 |
children | 694a7af7eaab |
files | liboctave/Sparse.h |
diffstat | 1 files changed, 6 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Sparse.h +++ b/liboctave/Sparse.h @@ -169,18 +169,17 @@ typename Sparse<T>::SparseRep *nil_rep (void) const { - static typename Sparse<T>::SparseRep *nr - = new typename Sparse<T>::SparseRep (); - - nr->count++; - - return nr; + static typename Sparse<T>::SparseRep nr; + return &nr; } public: Sparse (void) - : rep (nil_rep ()), dimensions (dim_vector(0,0)) { } + : rep (nil_rep ()), dimensions (dim_vector(0,0)) + { + rep->count++; + } explicit Sparse (octave_idx_type n) : rep (new typename Sparse<T>::SparseRep (n)),