Mercurial > octave-nkf
diff src/ov.cc @ 9546:1beb23d2b892
optimize op= in common cases
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 19 Aug 2009 13:47:59 +0200 |
parents | d9716e3ee0dd |
children | 1be3c73ed7b5 |
line wrap: on
line diff
--- a/src/ov.cc Mon Aug 17 14:46:18 2009 +0200 +++ b/src/ov.cc Wed Aug 19 13:47:59 2009 +0200 @@ -1195,10 +1195,6 @@ if (op != op_asn_eq) { - // FIXME -- only do the following stuff if we can't find - // a specific function to call to handle the op= operation for - // the types we have. - octave_value t = subsref (type, idx); if (! error_state) @@ -1236,19 +1232,41 @@ operator = (rhs.storable_value ()); else { - // FIXME -- only do the following stuff if we can't find - // a specific function to call to handle the op= operation for - // the types we have. - - binary_op binop = op_eq_to_binary_op (op); - - if (! error_state) + octave_value_typeinfo::assign_op_fcn f = 0; + + // Only attempt to operate in-place if this variable is unshared. + if (rep->count == 1) + { + int tthis = this->type_id (); + int trhs = rhs.type_id (); + + f = octave_value_typeinfo::lookup_assign_op (op, tthis, trhs); + } + + if (f) { - octave_value t = do_binary_op (binop, *this, rhs); - - if (! error_state) - operator = (t); + try + { + f (*rep, octave_value_list (), *rhs.rep); + } + catch (octave_execution_exception) + { + gripe_library_execution_error (); + } } + else + { + + binary_op binop = op_eq_to_binary_op (op); + + if (! error_state) + { + octave_value t = do_binary_op (binop, *this, rhs); + + if (! error_state) + operator = (t); + } + } if (error_state) gripe_assign_failed_or_no_method (assign_op_as_string (op),