changeset 30912:ec5b57af230a

Improve performance of inline functions. * NEWS.8.md: Announce compatibility and performance improvements. * scripts/legacy/@inline/inline.m: Add new field "fh" to inline class which holds an anonymous function handle implementing the inline function. Rename member variable "numArgs" to "nargs" to get away from CamelCase. * scripts/legacy/@inline/feval.m: Re-use existing class member variable "fh" to execute function rather than creating it every time feval() is called. * scripts/legacy/@inline/nargin.m: Update to use class member variable "nargs" rather than "numArgs".
author Rik <rik@octave.org>
date Wed, 06 Apr 2022 21:47:52 -0700
parents b7edac56a810
children a4ed2fed7dfa
files etc/NEWS.8.md scripts/legacy/@inline/feval.m scripts/legacy/@inline/inline.m scripts/legacy/@inline/nargin.m
diffstat 4 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/etc/NEWS.8.md	Wed Apr 06 21:25:58 2022 -0700
+++ b/etc/NEWS.8.md	Wed Apr 06 21:47:52 2022 -0700
@@ -8,7 +8,6 @@
 Configure with `--disable-lib-visibility-flags` to export all symbols
 (as in previous versions).
 
-
 ### Graphical User Interface
 
 
@@ -17,6 +16,9 @@
 
 ### Matlab compatibility
 
+- `inline` functions now support all Matlab methods.  The performance
+  of `inline` functions has also been improved.
+
 - `sub2ind` now supports index values outside of the size specified by
   the subscripts.
 
--- a/scripts/legacy/@inline/feval.m	Wed Apr 06 21:25:58 2022 -0700
+++ b/scripts/legacy/@inline/feval.m	Wed Apr 06 21:47:52 2022 -0700
@@ -25,8 +25,6 @@
 
 function retval = feval (fobj, varargin)
 
-  fh = eval (sprintf ("@(%s) %s", strjoin (fobj.args, ","), fobj.expr));
-
-  retval = fh (varargin{:});
+  retval = fobj.fh (varargin{:});
 
 endfunction
--- a/scripts/legacy/@inline/inline.m	Wed Apr 06 21:25:58 2022 -0700
+++ b/scripts/legacy/@inline/inline.m	Wed Apr 06 21:47:52 2022 -0700
@@ -97,7 +97,10 @@
 
   p.expr = expr;
   p.args = args(:);
-  p.numArgs = numel (args);
+  p.nargs = numel (args);
+  p.fh = eval (sprintf ("@(%s) %s", strjoin (args(:), ","), expr));
+
+  ## FIXME: Do we need these parts of inline struct anymore (4/6/22)?
   tmp = [args; num2cell(1:numel(args))];
   p.inputExpr = sprintf ("%s = INLINE_INPUTS_{%d}; ", tmp{:});
   p.isEmpty = false;
--- a/scripts/legacy/@inline/nargin.m	Wed Apr 06 21:25:58 2022 -0700
+++ b/scripts/legacy/@inline/nargin.m	Wed Apr 06 21:47:52 2022 -0700
@@ -32,6 +32,6 @@
 
 function n = nargin (fobj)
 
-  n = fobj.numArgs;
+  n = fobj.nargs;
 
 endfunction