changeset 9087:961410931a4f

fix nested struct assignments
author Jaroslav Hajek <highegg@gmail.com>
date Sat, 04 Apr 2009 20:00:18 +0200
parents 4218f9515258
children 77e71f3da3d6
files src/ChangeLog src/ov-struct.cc
diffstat 2 files changed, 21 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2009-04-04  Jaroslav Hajek  <highegg@gmail.com>
+
+	* ov-struct.cc (octave_struct::subsasgn): Fix reference counting
+	optimization.
+
 2008-04-03  David Bateman  <dbateman@free.fr>
 
 	* DLD-FUNCTIONS/max.cc (MINMAX_SPARSE_BODY): Allow sparse boolean 
--- a/src/ov-struct.cc
+++ b/src/ov-struct.cc
@@ -264,9 +264,6 @@
 
   octave_value t_rhs = rhs;
 
-  // This is handy for calling const methods of map.
-  const Octave_map& cmap = const_cast<const Octave_map &> (map);
-
   if (n > 1 && ! (type.length () == 2 && type[0] == '(' && type[1] == '.'))
     {
       switch (type[0])
@@ -294,16 +291,20 @@
 
                 std::string next_type = type.substr (2);
 
-                // cast map to const reference to avoid forced key insertion.
-                Cell tmpc = cmap.contents (key).index (idx.front (), true);
+                Cell tmpc (1, 1);
+                Octave_map::iterator pkey = map.seek (key);
+                if (pkey != map.end ())
+                  {
+                    pkey->second.make_unique ();
+                    tmpc = pkey->second.index (idx.front (), true);
+                  }
 
                 // FIXME: better code reuse? cf. octave_cell::subsasgn and the case below.
 		if (! error_state)
 		  {
                     if (tmpc.numel () == 1)
                       {
-                        octave_value tmp = tmpc(0);
-                        tmpc = Cell ();
+                        octave_value& tmp = tmpc(0);
 
                         if (! tmp.is_defined () || tmp.is_zero_by_zero ())
                           {
@@ -341,15 +342,19 @@
             std::string next_type = type.substr (1);
 
             Cell tmpc (1, 1);
-            if (map.contains (key)) tmpc = cmap.contents (key);
+            Octave_map::iterator pkey = map.seek (key);
+            if (pkey != map.end ())
+              {
+                pkey->second.make_unique ();
+                tmpc = pkey->second;
+              }
 
             // FIXME: better code reuse?
             if (! error_state)
               {
                 if (tmpc.numel () == 1)
                   {
-                    octave_value tmp = tmpc(0);
-                    tmpc = Cell ();
+                    octave_value& tmp = tmpc(0);
 
                     if (! tmp.is_defined () || tmp.is_zero_by_zero ())
                       {
@@ -422,6 +427,7 @@
                       }
                     else 
                       {
+                        const Octave_map& cmap = const_cast<const Octave_map &> (map);
                         // cast map to const reference to avoid forced key insertion.
                         if (idxf.all_scalars () 
                             || cmap.contents (key).index (idxf, true).numel () == 1)