comparison 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
comparison
equal deleted inserted replaced
9545:8670e55078fd 9546:1beb23d2b892
1193 1193
1194 octave_value t_rhs = rhs; 1194 octave_value t_rhs = rhs;
1195 1195
1196 if (op != op_asn_eq) 1196 if (op != op_asn_eq)
1197 { 1197 {
1198 // FIXME -- only do the following stuff if we can't find
1199 // a specific function to call to handle the op= operation for
1200 // the types we have.
1201
1202 octave_value t = subsref (type, idx); 1198 octave_value t = subsref (type, idx);
1203 1199
1204 if (! error_state) 1200 if (! error_state)
1205 { 1201 {
1206 binary_op binop = op_eq_to_binary_op (op); 1202 binary_op binop = op_eq_to_binary_op (op);
1234 if (op == op_asn_eq) 1230 if (op == op_asn_eq)
1235 // Regularize a null matrix if stored into a variable. 1231 // Regularize a null matrix if stored into a variable.
1236 operator = (rhs.storable_value ()); 1232 operator = (rhs.storable_value ());
1237 else 1233 else
1238 { 1234 {
1239 // FIXME -- only do the following stuff if we can't find 1235 octave_value_typeinfo::assign_op_fcn f = 0;
1240 // a specific function to call to handle the op= operation for 1236
1241 // the types we have. 1237 // Only attempt to operate in-place if this variable is unshared.
1242 1238 if (rep->count == 1)
1243 binary_op binop = op_eq_to_binary_op (op); 1239 {
1244 1240 int tthis = this->type_id ();
1245 if (! error_state) 1241 int trhs = rhs.type_id ();
1242
1243 f = octave_value_typeinfo::lookup_assign_op (op, tthis, trhs);
1244 }
1245
1246 if (f)
1246 { 1247 {
1247 octave_value t = do_binary_op (binop, *this, rhs); 1248 try
1248 1249 {
1249 if (! error_state) 1250 f (*rep, octave_value_list (), *rhs.rep);
1250 operator = (t); 1251 }
1252 catch (octave_execution_exception)
1253 {
1254 gripe_library_execution_error ();
1255 }
1251 } 1256 }
1257 else
1258 {
1259
1260 binary_op binop = op_eq_to_binary_op (op);
1261
1262 if (! error_state)
1263 {
1264 octave_value t = do_binary_op (binop, *this, rhs);
1265
1266 if (! error_state)
1267 operator = (t);
1268 }
1269 }
1252 1270
1253 if (error_state) 1271 if (error_state)
1254 gripe_assign_failed_or_no_method (assign_op_as_string (op), 1272 gripe_assign_failed_or_no_method (assign_op_as_string (op),
1255 type_name (), rhs.type_name ()); 1273 type_name (), rhs.type_name ());
1256 } 1274 }