# HG changeset patch # User Rik # Date 1379969003 25200 # Node ID b8ecdb6ce2f8e520813f00f06ea1ed264bdd75aa # Parent a5c6591d01e65f852f5b86b4aa83bd532715ade6 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. diff --git a/scripts/testfun/assert.m b/scripts/testfun/assert.m --- a/scripts/testfun/assert.m +++ b/scripts/testfun/assert.m @@ -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});