Mercurial > hg > octave-terminal
changeset 10614:d1194069e58c
optimize code handling ++,--
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sat, 08 May 2010 15:15:22 +0200 |
parents | e103fb2182ce |
children | 08050f37ba49 |
files | src/ChangeLog src/oct-lvalue.cc src/ov.cc src/ov.h src/pt-unop.cc |
diffstat | 5 files changed, 37 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2010-05-08 Jaroslav Hajek <highegg@gmail.com> + + * ov.cc (octave_value::do_non_const_unary_op): Always return *this as + octave_value&. Remove unused overload. + * oct-lvalue.cc (octave_lvalue::do_unary_op): Simplify. + * pt-unop.cc (tree_prefix_expression::rvalue1, + tree_postfix_expression::rvalue1): Remove dummy rvalue1 calls. + 2010-05-07 Michael Goffioul <michael.goffioul@gmail.com> * ov-base.h (Vsparse_auto_mutate): Add OCTINTERP_API tag.
--- a/src/oct-lvalue.cc +++ b/src/oct-lvalue.cc @@ -60,12 +60,10 @@ { if (val) { - octave_value tmp (idx.empty () - ? val->do_non_const_unary_op (op) - : val->do_non_const_unary_op (op, type, idx)); - - if (! error_state) - *val = tmp; + if (idx.empty ()) + val->do_non_const_unary_op (op); + else + val->do_non_const_unary_op (op, type, idx); } else error ("internal: invalid operation on ~");
--- a/src/ov.cc +++ b/src/ov.cc @@ -2328,11 +2328,22 @@ op.c_str (), tn.c_str ()); } -const octave_value& +octave_value& octave_value::do_non_const_unary_op (unary_op op) { if (op == op_incr || op == op_decr) { + // We want the gripe just here, because in the other branch this should + // not happen, and if it did anyway (internal error), the message would + // be confusing. + if (is_undefined ()) + { + std::string op_str = unary_op_as_string (op); + error ("in x%s or %sx, x must be defined first", + op_str.c_str (), op_str.c_str ()); + return *this; + } + // Genuine. int t = type_id (); @@ -2434,34 +2445,12 @@ return *this; } -#if 0 -static void -gripe_unary_op_failed_or_no_method (const std::string& on, - const std::string& tn) -{ - error ("operator %s: no method, or unable to evaluate for %s operand", - on.c_str (), tn.c_str ()); -} -#endif - -void -octave_value::do_non_const_unary_op (unary_op, const octave_value_list&) -{ - abort (); -} - -octave_value +octave_value& octave_value::do_non_const_unary_op (unary_op op, const std::string& type, const std::list<octave_value_list>& idx) { - octave_value retval; - if (idx.empty ()) - { - do_non_const_unary_op (op); - - retval = *this; - } + do_non_const_unary_op (op); else { // FIXME -- only do the following stuff if we can't find a @@ -2470,10 +2459,10 @@ assign_op assop = unary_op_to_assign_op (op); - retval = assign (assop, type, idx, 1.0); + assign (assop, type, idx, 1.0); } - return retval; + return *this; } octave_value::assign_op
--- a/src/ov.h +++ b/src/ov.h @@ -984,11 +984,9 @@ friend OCTINTERP_API octave_value do_unary_op (unary_op op, const octave_value& a); - const octave_value& do_non_const_unary_op (unary_op op); + octave_value& do_non_const_unary_op (unary_op op); - void do_non_const_unary_op (unary_op op, const octave_value_list& idx); - - octave_value do_non_const_unary_op (unary_op op, const std::string& type, + octave_value& do_non_const_unary_op (unary_op op, const std::string& type, const std::list<octave_value_list>& idx); friend OCTINTERP_API octave_value do_binary_op (binary_op op,
--- a/src/pt-unop.cc +++ b/src/pt-unop.cc @@ -69,18 +69,14 @@ { if (etype == octave_value::op_incr || etype == octave_value::op_decr) { - op->rvalue1 (); + octave_lvalue ref = op->lvalue (); if (! error_state) { - octave_lvalue ref = op->lvalue (); + ref.do_unary_op (etype); - if (! error_state && ref.is_defined ()) - { - ref.do_unary_op (etype); - - retval = ref.value (); - } + if (! error_state) + retval = ref.value (); } } else @@ -152,18 +148,13 @@ { if (etype == octave_value::op_incr || etype == octave_value::op_decr) { - op->rvalue1 (); + octave_lvalue ref = op->lvalue (); if (! error_state) { - octave_lvalue ref = op->lvalue (); + retval = ref.value (); - if (! error_state && ref.is_defined ()) - { - retval = ref.value (); - - ref.do_unary_op (etype); - } + ref.do_unary_op (etype); } } else