Mercurial > hg > octave-nkf
diff libinterp/corefcn/variables.cc @ 19051:da6ffbf75edf
Simplify exist() code for recognizing command line functions.
* variables.cc (symbol_exist): Short-circuit out quickly if search type is builtin and
no builtin is found. Use the fact that all other cases have been checked by the end
of the function to make the test for a command line function short.
* variables.cc (Fexist): Expand %!tests.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 25 Jun 2014 14:48:39 -0700 |
parents | a1dde4d4c45c |
children | c677d9bd6bac |
line wrap: on
line diff
--- a/libinterp/corefcn/variables.cc +++ b/libinterp/corefcn/variables.cc @@ -421,6 +421,9 @@ if ((search_any || search_builtin) && val.is_builtin_function ()) return 5; + + if (search_builtin) + return 0; } if (search_any || search_file || search_dir) @@ -474,21 +477,9 @@ return 0; } - if (val.is_defined ()) - { - if ((search_any || search_file) - && (val.is_user_function () || val.is_dld_function ())) - { - octave_function *f = val.function_value (true); - std::string s = f ? f->fcn_file_name () : std::string (); - - // FIXME: I believe that by this point in the code the only - // return value is 103. User functions should have - // been located above. Maybe replace entire if block - // code with "return 103;" - return s.empty () ? 103 : (val.is_user_function () ? 2 : 3); - } - } + // Command line function which Matlab does not support + if (search_any && val.is_defined () && val.is_user_function ()) + return 103; return 0; } @@ -610,6 +601,8 @@ %!assert (exist ("colon"), 2) %!assert (exist ("colon.m"), 2) +%!assert (exist ("colon", "file"), 2) +%!assert (exist ("colon", "dir"), 0) %!testif HAVE_CHOLMOD %! assert (exist ("chol"), 3); @@ -618,6 +611,8 @@ %! assert (exist ("chol", "builtin"), 0); %!assert (exist ("sin"), 5) +%!assert (exist ("sin", "builtin"), 5) +%!assert (exist ("sin", "file"), 0) %!assert (exist (dirtmp), 7) %!assert (exist (dirtmp, "dir"), 7)