Mercurial > octave
changeset 31825:8078a7f4edfa
Use data() instead of fortran_vec() where possible (bug #63803)
For all the instances of fortran_vec in libinterp/octave-value,
identify whether it can be treated as const, and replace
T *tmp = foo.fortran_vec ();
with
const T *tmp = foo.data ();
for those cases. This avoids the creation of a temporary copy,
saving memory and time.
Typically this pattern can be replaced when saving a variable to a
file, since the variable won't change at that point and can be
treated as const.
author | Arun Giridhar <arungiridhar@gmail.com> |
---|---|
date | Tue, 14 Feb 2023 18:55:11 -0500 |
parents | f14aea577cc5 |
children | fb8767c533d3 |
files | libinterp/octave-value/ov-bool-mat.cc libinterp/octave-value/ov-cx-mat.cc libinterp/octave-value/ov-flt-cx-mat.cc libinterp/octave-value/ov-flt-re-mat.cc libinterp/octave-value/ov-re-mat.cc libinterp/octave-value/ov-str-mat.cc |
diffstat | 6 files changed, 9 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-bool-mat.cc Tue Feb 14 14:39:23 2023 -0500 +++ b/libinterp/octave-value/ov-bool-mat.cc Tue Feb 14 18:55:11 2023 -0500 @@ -463,15 +463,11 @@ return false; } - octave_idx_type nel = m.numel (); - bool *mtmp = m.fortran_vec (); - OCTAVE_LOCAL_BUFFER (hbool_t, htmp, nel); - - for (octave_idx_type i = 0; i < nel; i++) - htmp[i] = mtmp[i]; + const bool *mtmp = m.data (); retval = H5Dwrite (data_hid, H5T_NATIVE_HBOOL, octave_H5S_ALL, octave_H5S_ALL, - octave_H5P_DEFAULT, htmp) >= 0; + octave_H5P_DEFAULT, + reinterpret_cast<const char*> (mtmp)) >= 0; H5Dclose (data_hid); H5Sclose (space_hid);
--- a/libinterp/octave-value/ov-cx-mat.cc Tue Feb 14 14:39:23 2023 -0500 +++ b/libinterp/octave-value/ov-cx-mat.cc Tue Feb 14 18:55:11 2023 -0500 @@ -613,7 +613,7 @@ if (retval) { - Complex *mtmp = m.fortran_vec (); + const Complex *mtmp = m.data (); if (H5Dwrite (data_hid, complex_type_hid, octave_H5S_ALL, octave_H5S_ALL, octave_H5P_DEFAULT, mtmp) < 0)
--- a/libinterp/octave-value/ov-flt-cx-mat.cc Tue Feb 14 14:39:23 2023 -0500 +++ b/libinterp/octave-value/ov-flt-cx-mat.cc Tue Feb 14 18:55:11 2023 -0500 @@ -569,7 +569,7 @@ if (retval) { - FloatComplex *mtmp = m.fortran_vec (); + const FloatComplex *mtmp = m.data (); if (H5Dwrite (data_hid, complex_type_hid, octave_H5S_ALL, octave_H5S_ALL, octave_H5P_DEFAULT, mtmp) < 0)
--- a/libinterp/octave-value/ov-flt-re-mat.cc Tue Feb 14 14:39:23 2023 -0500 +++ b/libinterp/octave-value/ov-flt-re-mat.cc Tue Feb 14 18:55:11 2023 -0500 @@ -631,7 +631,7 @@ return false; } - float *mtmp = m.fortran_vec (); + const float *mtmp = m.data (); retval = H5Dwrite (data_hid, H5T_NATIVE_FLOAT, octave_H5S_ALL, octave_H5S_ALL, octave_H5P_DEFAULT, mtmp) >= 0;
--- a/libinterp/octave-value/ov-re-mat.cc Tue Feb 14 14:39:23 2023 -0500 +++ b/libinterp/octave-value/ov-re-mat.cc Tue Feb 14 18:55:11 2023 -0500 @@ -757,7 +757,7 @@ return false; } - double *mtmp = m.fortran_vec (); + const double *mtmp = m.data (); retval = H5Dwrite (data_hid, H5T_NATIVE_DOUBLE, octave_H5S_ALL, octave_H5S_ALL, octave_H5P_DEFAULT, mtmp) >= 0;
--- a/libinterp/octave-value/ov-str-mat.cc Tue Feb 14 14:39:23 2023 -0500 +++ b/libinterp/octave-value/ov-str-mat.cc Tue Feb 14 18:55:11 2023 -0500 @@ -328,7 +328,7 @@ for (int i=0; i < dv.ndims (); i++) os << ' ' << dv(i); os << "\n"; - os.write (tmp.fortran_vec (), dv.numel ()); + os.write (tmp.data (), dv.numel ()); os << "\n"; } else @@ -486,7 +486,7 @@ } charNDArray m = char_array_value (); - os.write (m.fortran_vec (), dv.numel ()); + os.write (m.data (), dv.numel ()); return true; }