# HG changeset patch # User John W. Eaton # Date 1631813200 14400 # Node ID 2429561a141525edbbc68c729f8675512573a13e # Parent 41eecdf763728b559c508497771a575060aaca52 replace sub2ind helper classes with lambda expression * Array-util.cc (sub2ind_helper): Delete. (sub2ind): Use lambda expression instead of sub2ind_helper class instance. diff -r 41eecdf76372 -r 2429561a1415 liboctave/array/Array-util.cc --- a/liboctave/array/Array-util.cc Thu Sep 16 12:54:15 2021 -0400 +++ b/liboctave/array/Array-util.cc Thu Sep 16 13:26:40 2021 -0400 @@ -520,19 +520,6 @@ return rdv; } -// A helper class. -class sub2ind_helper -{ -public: - sub2ind_helper (octave_idx_type *ind, octave_idx_type n) - : m_ind (ind), m_n (n) { } - - void operator () (octave_idx_type k) { (*m_ind++ *= m_n) += k; } - -private: - octave_idx_type *m_ind, m_n; -}; - octave::idx_vector sub2ind (const dim_vector& dv, const Array& idxa) { @@ -602,12 +589,22 @@ else { Array idx (idxa(0).orig_dimensions ()); - octave_idx_type *idx_vec = idx.fortran_vec (); for (octave_idx_type i = len - 1; i >= 0; i--) { + // Initialized inside the loop so that each call to + // idx_vector::loop operates from the beginning of IDX_VEC. + + octave_idx_type *idx_vec = idx.fortran_vec (); + if (i < len - 1) - idxa(i).loop (clen, sub2ind_helper (idx_vec, dvx(i))); + { + octave_idx_type n = dvx(i); + + idxa(i).loop (clen, [=, &idx_vec] (octave_idx_type k) { + (*idx_vec++ *= n) += k; + }); + } else idxa(i).copy_data (idx_vec); }