Mercurial > hg > octave-nkf
changeset 8379:ad8ed668e0a4
allow initialized local buffers
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sat, 06 Dec 2008 09:15:44 +0100 |
parents | 7d0492aa522d |
children | dbe67764e628 |
files | liboctave/Array.cc liboctave/ChangeLog liboctave/idx-vector.cc liboctave/oct-locbuf.h |
diffstat | 4 files changed, 18 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -1915,10 +1915,7 @@ } else { - // Don't use OCTAVE_LOCAL_BUFFER here as it doesn't work with bool - // on some compilers. - Array<T> vi (ns); - T *pvi = vi.fortran_vec (); + OCTAVE_LOCAL_BUFFER (T, pvi, ns); for (octave_idx_type j = 0; j < iter; j++) {
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,7 @@ +2008-12-06 Jaroslav Hajek <highegg@gmail.com> + + * oct-locbuf.h (OCTAVE_LOCAL_BUFFER_INIT): New macro. + 2008-10-29 Jaroslav Hajek <highegg@gmail.com> * oct-locbuf.h: New header file.
--- a/liboctave/idx-vector.cc +++ b/liboctave/idx-vector.cc @@ -34,6 +34,7 @@ #include "Array.h" #include "Range.h" +#include "oct-locbuf.h" #include "lo-error.h" #include "lo-mappers.h" @@ -502,10 +503,7 @@ idx_vector idx_vector::complement (octave_idx_type n) const { - - bool *left = new bool[n]; - - std::fill (left, left + n, true); + OCTAVE_LOCAL_BUFFER_INIT (bool, left, n, true); octave_idx_type cnt = n; @@ -522,8 +520,6 @@ octave_idx_type len = cnt, *data = new octave_idx_type[len]; for (octave_idx_type i = 0, j = 0; i < n; i++) if (left[i]) data[j++] = i; - - delete [] left; return new idx_vector_rep (data, len, len ? data[len-1]+1 : 0, @@ -539,9 +535,7 @@ retval = true; else if (length (n) == n && extent(n) == n) { - bool *left = new bool[n]; - - std::fill (left, left + n, true); + OCTAVE_LOCAL_BUFFER_INIT (bool, left, n, true); retval = true; @@ -557,7 +551,6 @@ } } - delete [] left; } return retval;
--- a/liboctave/oct-locbuf.h +++ b/liboctave/oct-locbuf.h @@ -65,7 +65,7 @@ <= OCTAVE_LOCAL_BUFFER_MAX_STACK_SIZE; \ T _bufaut_ ## buf [_lbufaut_ ## buf ? _bufsize_ ## buf : 0]; \ octave_local_buffer<T> _bufheap_ ## buf (!_lbufaut_ ## buf ? _bufsize_ ## buf : 0); \ - T *buf = _lbufaut_ ## buf ? _bufaut_ ## buf : static_cast<T *> (_bufheap_ ## buf); + T *buf = _lbufaut_ ## buf ? _bufaut_ ## buf : static_cast<T *> (_bufheap_ ## buf) #else @@ -73,9 +73,17 @@ #define OCTAVE_LOCAL_BUFFER(T, buf, size) \ octave_local_buffer<T> _buffer_ ## buf (size); \ - T *buf = _buffer_ ## buf; + T *buf = _buffer_ ## buf #endif +// Yeah overloading macros would be nice. +// Note: we use weird variables in the for loop to avoid warnings about +// shadowed parameters. +#define OCTAVE_LOCAL_BUFFER_INIT(T, buf, size, value) \ + OCTAVE_LOCAL_BUFFER(T, buf, size); \ + for (size_t _buf_iter = 0, _buf_size = size; \ + _buf_iter < _buf_size; _buf_iter++) buf[_buf_iter] = value + #endif