changeset 22640:58c1c6aeb737 stable

odeset: Improve performance by using for loop for merging of unknown options. * odeset.m: Only merge default odestruct with the list of unmatched properties, odestruct_extra, if there are actually properties to be merged. When merging, use a for loop rather to merge each additional property rather than more complicated cellfun, cell array, struct() sequence. Sort unmatched options so they are added in alphabetical order after the list of known options.
author Rik <rik@octave.org>
date Wed, 19 Oct 2016 08:28:13 -0700
parents 7efa2d0e22c9
children c28648e039da
files scripts/ode/odeset.m
diffstat 1 files changed, 7 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ode/odeset.m	Tue Oct 18 11:31:13 2016 -0700
+++ b/scripts/ode/odeset.m	Wed Oct 19 08:28:13 2016 -0700
@@ -190,22 +190,14 @@
     odestruct = p.Results;
     odestruct_extra = p.Unmatched;
 
-    ## FIXME: For speed, shouldn't this merge of structures only occur
-    ##        when there is something in odestruct_extra?
-    ## FIXME: Should alphabetical order of fieldnames be maintained
-    ##        by using sort?
-    s1 = cellfun (@(x) ifelse (iscell (x), {x}, x),
-                  struct2cell (odestruct),
-                  "UniformOutput", false);
+    xtra_fields = fieldnames (odestruct_extra);
+    if (! isempty (xtra_fields))
+      ## Merge extra fields into existing odestruct
+      for fldname = sort (xtra_fields.')
+        odestruct.(fldname{1}) = odestruct_extra.(fldname{1});
+      endfor
+    endif
 
-    s2 = cellfun (@(x) ifelse (iscell (x), {x}, x),
-                  struct2cell (odestruct_extra),
-                  "UniformOutput", false);
-
-    C = [fieldnames(odestruct)       s1;
-         fieldnames(odestruct_extra) s2];
-
-    odestruct = struct (C'{:});
   endif
 
 endfunction