Mercurial > hg > octave-nkf
changeset 9413:5cd879a0d8c4
speed-up function call by caching its name lookup
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 01 Jul 2009 10:42:58 +0200 |
parents | ddcc0da700b8 |
children | 79c4dd83d07f |
files | src/ChangeLog src/symtab.cc src/symtab.h |
diffstat | 3 files changed, 36 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2009-07-01 Jaroslav Hajek <highegg@gmail.com> + + * symtab.h (symbol_table::get_fcn_info): New private static method. + (symbol_record_rep::finfo): New field. + * symtab.cc (symbol_record::find): Use cached finfo if possible, + cache on successful queries. + 2008-07-01 David Bateman <dbateman@free.fr> * pr-output.cc (static inline std::string rational_approx (double,
--- a/src/symtab.cc +++ b/src/symtab.cc @@ -104,17 +104,29 @@ octave_value retval; if (is_global ()) - return symbol_table::global_varref (name ()); + retval = symbol_table::global_varref (name ()); else { - octave_value val = varval (); + retval = varval (); - if (val.is_defined ()) - return val; + if (retval.is_undefined ()) + { + // Use cached fcn_info pointer if possible. + if (rep->finfo) + retval = rep->finfo->find (args, arg_names, + evaluated_args, args_evaluated); + else + { + retval = symbol_table::find_function (name (), args, arg_names, + evaluated_args, args_evaluated); + + if (retval.is_defined ()) + rep->finfo = get_fcn_info (name ()); + } + } } - return symbol_table::find_function (name (), args, arg_names, - evaluated_args, args_evaluated); + return retval; } // Check the load path to see if file that defined this is still
--- a/src/symtab.h +++ b/src/symtab.h @@ -155,6 +155,8 @@ } }; + class fcn_info; + class symbol_record { @@ -194,7 +196,7 @@ symbol_record_rep (const std::string& nm, const octave_value& v, unsigned int sc) - : name (nm), value_stack (), storage_class (sc), count (1) + : name (nm), value_stack (), storage_class (sc), finfo (), count (1) { value_stack.push_back (v); } @@ -372,6 +374,8 @@ unsigned int storage_class; + fcn_info *finfo; + size_t count; private: @@ -1988,6 +1992,12 @@ } } + static fcn_info *get_fcn_info (const std::string& name) + { + fcn_table_iterator p = fcn_table.find (name); + return p != fcn_table.end () ? &p->second : 0; + } + octave_value do_find (const std::string& name, tree_argument_list *args, const string_vector& arg_names,