Mercurial > hg > octave-lyh
comparison src/ov-struct.cc @ 8456:c1709a45b45b
optimize structure components access
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sun, 11 Jan 2009 14:27:52 +0100 |
parents | 25bc2d31e1bf |
children | ad3afaaa19c1 |
comparison
equal
deleted
inserted
replaced
8455:fd11a08a9b31 | 8456:c1709a45b45b |
---|---|
222 | 222 |
223 if (! map.contains (key)) | 223 if (! map.contains (key)) |
224 u = octave_value::empty_conv (type.substr (2), rhs); | 224 u = octave_value::empty_conv (type.substr (2), rhs); |
225 else | 225 else |
226 { | 226 { |
227 Cell map_val = map.contents (key); | 227 Cell& cell_ref = map.contents (key); |
228 | 228 |
229 Cell map_elt = map_val.index (idx.front (), true); | 229 octave_value u1 = cell_ref.index (idx.front (), true); |
230 | 230 u = numeric_conv (u1, type.substr (2)); |
231 u = numeric_conv (map_elt, type.substr (2)); | 231 |
232 if (u.is_defined () && u.is_copy_of (u1)) | |
233 { | |
234 // This is a bit of black magic. u is a shallow copy | |
235 // of an element inside this struct, and maybe more. To | |
236 // prevent make_unique from always forcing a copy, we | |
237 // temporarily delete the stored value. | |
238 u1 = octave_value (); | |
239 cell_ref.assign (idx.front (), Cell (octave_value ())); | |
240 u.make_unique (); | |
241 cell_ref.assign (idx.front (), Cell (u)); | |
242 } | |
243 else | |
244 // Safe is safe. | |
245 u.make_unique (); | |
246 | |
232 } | 247 } |
233 | 248 |
234 if (! error_state) | 249 if (! error_state) |
235 { | 250 { |
236 std::list<octave_value_list> next_idx (idx); | 251 std::list<octave_value_list> next_idx (idx); |
238 // We handled two index elements, so subsasgn to | 253 // We handled two index elements, so subsasgn to |
239 // needs to skip both of them. | 254 // needs to skip both of them. |
240 | 255 |
241 next_idx.erase (next_idx.begin ()); | 256 next_idx.erase (next_idx.begin ()); |
242 next_idx.erase (next_idx.begin ()); | 257 next_idx.erase (next_idx.begin ()); |
243 | |
244 u.make_unique (); | |
245 | 258 |
246 t_rhs = u.subsasgn (type.substr (2), next_idx, rhs); | 259 t_rhs = u.subsasgn (type.substr (2), next_idx, rhs); |
247 } | 260 } |
248 } | 261 } |
249 else | 262 else |
263 | 276 |
264 if (! map.contains (key)) | 277 if (! map.contains (key)) |
265 u = octave_value::empty_conv (type.substr (1), rhs); | 278 u = octave_value::empty_conv (type.substr (1), rhs); |
266 else | 279 else |
267 { | 280 { |
268 Cell map_val = map.contents (key); | 281 Cell& cell_ref = map.contents (key); |
269 | 282 |
270 u = numeric_conv (map_val, type.substr (1)); | 283 u = numeric_conv (cell_ref, type.substr (2)); |
284 | |
285 if (u.is_defined () && u.is_copy_of (cell_ref(0))) | |
286 { | |
287 // This is a bit of black magic. u is a shallow copy | |
288 // of an element inside this struct, and maybe more. To | |
289 // prevent make_unique from always forcing a copy, we | |
290 // temporarily delete the stored value. | |
291 cell_ref(0) = octave_value (); | |
292 u.make_unique (); | |
293 cell_ref(0) = u; | |
294 } | |
295 else | |
296 // Safe is safe. | |
297 u.make_unique (); | |
271 } | 298 } |
272 | 299 |
273 if (! error_state) | 300 if (! error_state) |
274 { | 301 { |
275 std::list<octave_value_list> next_idx (idx); | 302 std::list<octave_value_list> next_idx (idx); |
276 | 303 |
277 next_idx.erase (next_idx.begin ()); | 304 next_idx.erase (next_idx.begin ()); |
278 | |
279 u.make_unique (); | |
280 | 305 |
281 t_rhs = u.subsasgn (type.substr (1), next_idx, rhs); | 306 t_rhs = u.subsasgn (type.substr (1), next_idx, rhs); |
282 } | 307 } |
283 } | 308 } |
284 break; | 309 break; |