# HG changeset patch # User Jaroslav Hajek
# Date 1238826656 -7200 # Node ID 5d6d0bc9aeb4fdbfa6d360e060383135bdfa8ecd # Parent b7210faa3ed0d9b52d730309c88c46668d1cb836 optimize simple stack operations on arrays diff --git a/liboctave/Array.cc b/liboctave/Array.cc --- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -53,14 +53,6 @@ { --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; } } @@ -1072,7 +1064,36 @@ else { octave_idx_type nx = numel (); - if (n != nx) + if (n == nx - 1 && n > 0) + { + // Stack "pop" operation. + if (rep->count == 1) + slice_data[slice_len-1] = T (); + slice_len--; + dimensions = dv; + } + else if (n == nx + 1 && nx > 0) + { + // Stack "push" operation. + if (rep->count == 1 && slice_data + slice_len < rep->data + rep->len) + { + slice_data[slice_len++] = rfv; + dimensions = dv; + } + else + { + static const octave_idx_type max_stack_chunk = 1024; + octave_idx_type nn = n + std::min (nx, max_stack_chunk); + Array