Mercurial > hg > octave-lyh
diff src/ov-struct.cc @ 10760:76079e505f9d
optimize cellfun with uniform struct output
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 01 Jul 2010 08:51:14 +0200 |
parents | 92eb5fb58ebc |
children | 89f4d7e294cc |
line wrap: on
line diff
--- a/src/ov-struct.cc +++ b/src/ov-struct.cc @@ -1074,6 +1074,33 @@ return retval; } +octave_value +octave_struct::fast_elem_extract (octave_idx_type n) const +{ + if (n < map.numel ()) + return map.checkelem (n); + else + return octave_value (); +} + +bool +octave_struct::fast_elem_insert (octave_idx_type n, + const octave_value& x) +{ + bool retval = false; + + if (n < map.numel ()) + { + // To avoid copying the scalar struct, it just stores a pointer to + // itself. + const octave_scalar_map *sm_ptr; + void *here = reinterpret_cast<void *>(&sm_ptr); + return (x.get_rep().fast_elem_insert_self (here, btyp_struct) + && map.fast_elem_insert (n, *sm_ptr)); + } + + return retval; +} DEFINE_OCTAVE_ALLOCATOR(octave_scalar_struct); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(octave_scalar_struct, "scalar struct", "struct"); @@ -1682,6 +1709,18 @@ return new octave_struct (octave_map (map)); } +bool +octave_scalar_struct::fast_elem_insert_self (void *where, builtin_type_t btyp) const +{ + + if (btyp == btyp_struct) + { + *(reinterpret_cast<const octave_scalar_map **>(where)) = ↦ + return true; + } + else + return false; +} /* %!shared x %! x(1).a=1; x(2).a=2; x(1).b=3; x(2).b=3;