Mercurial > hg > octave-nkf
changeset 5007:f8c27dad3643
[project @ 2004-09-17 11:42:04 by jwe]
author | jwe |
---|---|
date | Fri, 17 Sep 2004 11:42:04 +0000 |
parents | 2bcd013bc867 |
children | c2bb27ada496 |
files | src/ChangeLog src/ov-fcn-handle.h src/ov-fcn-inline.cc |
diffstat | 3 files changed, 28 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2004-09-17 John W. Eaton <jwe@octave.org> + + * 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 <jwe@octave.org> * parse.y (frob_function): Clear id_name from curr_sym_tab, not
--- a/src/ov-fcn-handle.h +++ b/src/ov-fcn-handle.h @@ -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,
--- a/src/ov-fcn-inline.cc +++ b/src/ov-fcn-inline.cc @@ -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"); }