changeset 17467:b8ecdb6ce2f8

assert.m: Speed up function by ~16% by not pre-calculating warning message. * scripts/testfun/assert.m: Don't pre-calculate "in" warning message since it is only used a small fraction of the time when there is an actual error.
author Rik <rik@octave.org>
date Mon, 23 Sep 2013 13:43:23 -0700
parents a5c6591d01e6
children fc4df284efc8
files scripts/testfun/assert.m
diffstat 1 files changed, 6 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/testfun/assert.m	Mon Sep 23 12:11:21 2013 -0700
+++ b/scripts/testfun/assert.m	Mon Sep 23 13:43:23 2013 -0700
@@ -69,18 +69,13 @@
     errmsg = "";
   endif
 
-  in = deblank (argn(1,:));
-  for i = 2:rows (argn)
-    in = [in "," deblank(argn(i,:))];
-  endfor
-  in = ["(" in ")"];
-
   if (nargin == 1 || (nargin > 1 && islogical (cond) && ischar (varargin{1})))
     if ((! isnumeric (cond) && ! islogical (cond)) || ! all (cond(:)))
       call_depth--;
       if (nargin == 1)
         ## Perhaps, say which elements failed?
-        error ("assert %s failed", in);
+        argin = ["(" strjoin(cellstr (argn), ",") ")"];
+        error ("assert %s failed", argin);
       else
         error (varargin{:});
       endif
@@ -363,10 +358,11 @@
 
     ## Print any errors
     if (! isempty (err.index))
+      argin = ["(" strjoin(cellstr (argn), ",") ")"];
       if (! isempty (errmsg))
         errmsg = [errmsg "\n"];
       endif
-      errmsg = [errmsg, pprint(in, err)];
+      errmsg = [errmsg, pprint(argin, err)];
     endif
 
   endif
@@ -629,9 +625,9 @@
 
 
 ## Pretty print the various errors in a condensed tabular format.
-function str = pprint (in, err)
+function str = pprint (argin, err)
 
-  str = ["ASSERT errors for:  assert " in "\n"];
+  str = ["ASSERT errors for:  assert " argin "\n"];
   str = [str, "\n  Location  |  Observed  |  Expected  |  Reason\n"];
   for i = 1:length (err.index)
     leni = length (err.index{i});