# HG changeset patch # User Jaroslav Hajek # Date 1228551344 -3600 # Node ID ad8ed668e0a44e97983e2e05b80d3439be50ccb5 # Parent 7d0492aa522d5598b4ee51a57a46b6a3adba5bb2 allow initialized local buffers diff --git a/liboctave/Array.cc b/liboctave/Array.cc --- 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 vi (ns); - T *pvi = vi.fortran_vec (); + OCTAVE_LOCAL_BUFFER (T, pvi, ns); for (octave_idx_type j = 0; j < iter; j++) { diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog --- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,7 @@ +2008-12-06 Jaroslav Hajek + + * oct-locbuf.h (OCTAVE_LOCAL_BUFFER_INIT): New macro. + 2008-10-29 Jaroslav Hajek * oct-locbuf.h: New header file. diff --git a/liboctave/idx-vector.cc b/liboctave/idx-vector.cc --- 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; diff --git a/liboctave/oct-locbuf.h b/liboctave/oct-locbuf.h --- 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 _bufheap_ ## buf (!_lbufaut_ ## buf ? _bufsize_ ## buf : 0); \ - T *buf = _lbufaut_ ## buf ? _bufaut_ ## buf : static_cast (_bufheap_ ## buf); + T *buf = _lbufaut_ ## buf ? _bufaut_ ## buf : static_cast (_bufheap_ ## buf) #else @@ -73,9 +73,17 @@ #define OCTAVE_LOCAL_BUFFER(T, buf, size) \ octave_local_buffer _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