# HG changeset patch # User Rik # Date 1629139540 25200 # Node ID 06bf5aca68bb74932e9ad3bf092c71e014a2666a # Parent 65c6095040360d5bb73058097b9a867c1e72d581 Improve performance of sort along dimensions > 1 (bug #60928). * Array.cc (sort (dim, mode), sort (&sidx, dim, mode)): Replace calculation of offset using while loop with division and multiplication of integers. diff -r 65c609504036 -r 06bf5aca68bb liboctave/array/Array.cc --- a/liboctave/array/Array.cc Mon Aug 16 19:16:58 2021 +0200 +++ b/liboctave/array/Array.cc Mon Aug 16 11:45:40 2021 -0700 @@ -1830,15 +1830,8 @@ for (octave_idx_type j = 0; j < iter; j++) { octave_idx_type offset = j; - octave_idx_type offset2 = 0; - - while (offset >= stride) - { - offset -= stride; - offset2++; - } - - offset += offset2 * stride * ns; + octave_idx_type n_strides = j / stride; + offset += n_strides * stride * (ns - 1); // gather and partition out NaNs. // FIXME: impact on integer types noticeable? @@ -1964,15 +1957,8 @@ for (octave_idx_type j = 0; j < iter; j++) { octave_idx_type offset = j; - octave_idx_type offset2 = 0; - - while (offset >= stride) - { - offset -= stride; - offset2++; - } - - offset += offset2 * stride * ns; + octave_idx_type n_strides = j / stride; + offset += n_strides * stride * (ns - 1); // gather and partition out NaNs. // FIXME: impact on integer types noticeable?