# HG changeset patch # User jwe # Date 1095421324 0 # Node ID f8c27dad3643214387b36b8a3e2ae7a6a8c07890 # Parent 2bcd013bc8673ce82c7142684ae53d78b9eefe37 [project @ 2004-09-17 11:42:04 by jwe] diff -r 2bcd013bc867 -r f8c27dad3643 src/ChangeLog --- a/src/ChangeLog Fri Sep 17 02:59:53 2004 +0000 +++ b/src/ChangeLog Fri Sep 17 11:42:04 2004 +0000 @@ -1,3 +1,14 @@ +2004-09-17 John W. Eaton + + * ov-fcn-inline.cc (octave_fcn_inline::octave_fcn_inline): + Call eval_string instead of feval ("eval", ...). + Construct anonymous function handle to avoid going through the + symbol table. + + * ov-fcn-handle.h (octave_fcn_handle::fcn_val): New function. + (octave_fcn_handle::octave_fcn_handle (const std:string&)): + New constructor. + 2004-09-16 John W. Eaton * parse.y (frob_function): Clear id_name from curr_sym_tab, not diff -r 2bcd013bc867 -r f8c27dad3643 src/ov-fcn-handle.h --- a/src/ov-fcn-handle.h Fri Sep 17 02:59:53 2004 +0000 +++ b/src/ov-fcn-handle.h Fri Sep 17 11:42:04 2004 +0000 @@ -46,6 +46,9 @@ octave_fcn_handle (void) : fcn (), nm () { } + octave_fcn_handle (const std::string& n) + : fcn (), nm (n) { } + octave_fcn_handle (const octave_value& f, const std::string& n) : fcn (f), nm (n) { } @@ -77,6 +80,8 @@ octave_fcn_handle *fcn_handle_value (bool = false) { return this; } + octave_value fcn_val (void) const { return fcn; } + std::string fcn_name (void) const { return nm; } bool save_ascii (std::ostream& os, bool& infnan_warned, diff -r 2bcd013bc867 -r f8c27dad3643 src/ov-fcn-inline.cc --- a/src/ov-fcn-inline.cc Fri Sep 17 02:59:53 2004 +0000 +++ b/src/ov-fcn-inline.cc Fri Sep 17 11:42:04 2004 +0000 @@ -58,16 +58,13 @@ octave_fcn_inline::octave_fcn_inline (const std::string& f, const string_vector& a, const std::string& n) - : octave_fcn_handle (0, n), iftext (f), ifargs (a) + : octave_fcn_handle (n), iftext (f), ifargs (a) { - // Find a function name that isn't already in the symbol table. - std::string fname = unique_symbol_name ("__inline_"); - // Form a string representing the function. OSSTREAM buf; - buf << "function __retval__ = " << fname << "("; + buf << "@("; for (int i = 0; i < ifargs.length (); i++) { @@ -77,25 +74,23 @@ buf << ifargs(i); } - buf << ")\n __retval__ = " << iftext << ";\nendfunction" << OSSTREAM_ENDS; - - // Parse this function and create a user function. + buf << ") " << iftext << OSSTREAM_ENDS; - octave_value eval_args (OSSTREAM_STR (buf)); - - feval ("eval", eval_args, 0); + int parse_status; + octave_value anon_fcn_handle = eval_string (OSSTREAM_STR (buf), true, + parse_status); OSSTREAM_FREEZE (buf); - octave_value tmp = lookup_function (fname); - - if (tmp.is_function ()) + if (parse_status == 0) { - fcn = tmp; + octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); - clear_function (fname); + if (fh) + fcn = fh->fcn_val (); } - else + + if (fcn.is_undefined ()) error ("inline: unable to define function"); }