diff libinterp/octave-value/ov-struct.cc @ 20593:c41595061186

eliminate more simple uses of error_state * betainc.cc, file-io.cc, ov-class.cc, ov-struct.cc: Eliminate simple uses of error_state.
author John W. Eaton <jwe@octave.org>
date Mon, 05 Oct 2015 23:09:54 -0400
parents c6224b4e7774
children eef93a493ce3
line wrap: on
line diff
--- a/libinterp/octave-value/ov-struct.cc	Mon Oct 05 22:47:42 2015 -0400
+++ b/libinterp/octave-value/ov-struct.cc	Mon Oct 05 23:09:54 2015 -0400
@@ -153,17 +153,14 @@
 
             const Cell tmp = dotref (key_idx);
 
-            if (! error_state)
-              {
-                const Cell t = tmp.index (idx.front ());
-
-                retval(0) = (t.numel () == 1) ? t(0) : octave_value (t, true);
-
-                // We handled two index elements, so tell
-                // next_subsref to skip both of them.
-
-                skip++;
-              }
+            const Cell t = tmp.index (idx.front ());
+
+            retval(0) = (t.numel () == 1) ? t(0) : octave_value (t, true);
+
+            // We handled two index elements, so tell
+            // next_subsref to skip both of them.
+
+            skip++;
           }
         else
           retval(0) = do_index_op (idx.front ());
@@ -219,17 +216,14 @@
 
             const Cell tmp = dotref (key_idx, auto_add);
 
-            if (! error_state)
-              {
-                const Cell t = tmp.index (idx.front (), auto_add);
-
-                retval = (t.numel () == 1) ? t(0) : octave_value (t, true);
-
-                // We handled two index elements, so tell
-                // next_subsref to skip both of them.
-
-                skip++;
-              }
+            const Cell t = tmp.index (idx.front (), auto_add);
+
+            retval = (t.numel () == 1) ? t(0) : octave_value (t, true);
+
+            // We handled two index elements, so tell
+            // next_subsref to skip both of them.
+
+            skip++;
           }
         else
           retval = do_index_op (idx.front (), auto_add);
@@ -324,9 +318,6 @@
 
                 maybe_warn_invalid_field_name (key, "subsasgn");
 
-                if (error_state)
-                  return retval;
-
                 std::list<octave_value_list> next_idx (idx);
 
                 // We handled two index elements, so subsasgn to
@@ -347,33 +338,28 @@
 
                 // FIXME: better code reuse?
                 //        cf. octave_cell::subsasgn and the case below.
-                if (! error_state)
+                if (tmpc.numel () == 1)
                   {
-                    if (tmpc.numel () == 1)
+                    octave_value& tmp = tmpc(0);
+
+                    bool orig_undefined = tmp.is_undefined ();
+
+                    if (orig_undefined || tmp.is_zero_by_zero ())
                       {
-                        octave_value& tmp = tmpc(0);
-
-                        bool orig_undefined = tmp.is_undefined ();
-
-                        if (orig_undefined || tmp.is_zero_by_zero ())
-                          {
-                            tmp = octave_value::empty_conv (next_type, rhs);
-                            tmp.make_unique (); // probably a no-op.
-                          }
-                        else
-                          // optimization: ignore the copy
-                          // still stored inside our map.
-                          tmp.make_unique (1);
-
-                        if (! error_state)
-                          t_rhs =
-                            (orig_undefined
-                               ? tmp.undef_subsasgn (next_type, next_idx, rhs)
-                               : tmp.subsasgn (next_type, next_idx, rhs));
+                        tmp = octave_value::empty_conv (next_type, rhs);
+                        tmp.make_unique (); // probably a no-op.
                       }
                     else
-                      gripe_indexed_cs_list ();
+                      // optimization: ignore the copy
+                      // still stored inside our map.
+                      tmp.make_unique (1);
+
+                      t_rhs =(orig_undefined
+                              ? tmp.undef_subsasgn (next_type, next_idx, rhs)
+                              : tmp.subsasgn (next_type, next_idx, rhs));
                   }
+                else
+                  gripe_indexed_cs_list ();
               }
             else
               gripe_invalid_index_for_assignment ();
@@ -390,9 +376,6 @@
 
             maybe_warn_invalid_field_name (key, "subsasgn");
 
-            if (error_state)
-              return retval;
-
             std::list<octave_value_list> next_idx (idx);
 
             next_idx.erase (next_idx.begin ());
@@ -408,32 +391,29 @@
               }
 
             // FIXME: better code reuse?
-            if (! error_state)
+
+            if (tmpc.numel () == 1)
               {
-                if (tmpc.numel () == 1)
+                octave_value& tmp = tmpc(0);
+
+                bool orig_undefined = tmp.is_undefined ();
+
+                if (orig_undefined || tmp.is_zero_by_zero ())
                   {
-                    octave_value& tmp = tmpc(0);
-
-                    bool orig_undefined = tmp.is_undefined ();
-
-                    if (orig_undefined || tmp.is_zero_by_zero ())
-                      {
-                        tmp = octave_value::empty_conv (next_type, rhs);
-                        tmp.make_unique (); // probably a no-op.
-                      }
-                    else
-                      // optimization: ignore the copy
-                      // still stored inside our map.
-                      tmp.make_unique (1);
-
-                    if (! error_state)
-                      t_rhs = (orig_undefined
-                               ? tmp.undef_subsasgn (next_type, next_idx, rhs)
-                               : tmp.subsasgn (next_type, next_idx, rhs));
+                    tmp = octave_value::empty_conv (next_type, rhs);
+                    tmp.make_unique (); // probably a no-op.
                   }
                 else
-                  gripe_indexed_cs_list ();
+                  // optimization: ignore the copy
+                  // still stored inside our map.
+                  tmp.make_unique (1);
+
+                t_rhs = (orig_undefined
+                         ? tmp.undef_subsasgn (next_type, next_idx, rhs)
+                         : tmp.subsasgn (next_type, next_idx, rhs));
               }
+            else
+              gripe_indexed_cs_list ();
           }
           break;
 
@@ -464,9 +444,6 @@
 
                 maybe_warn_invalid_field_name (key, "subsasgn");
 
-                if (error_state)
-                  return retval;
-
                 if (! error_state)
                   {
                     if (t_rhs.is_cs_list ())
@@ -572,9 +549,6 @@
 
             maybe_warn_invalid_field_name (key, "subsasgn");
 
-            if (error_state)
-              return retval;
-
             if (t_rhs.is_cs_list ())
               {
                 Cell tmp_cell = Cell (t_rhs.list_value ());
@@ -1156,9 +1130,6 @@
 
   maybe_warn_invalid_field_name (nm, "subsref");
 
-  if (error_state)
-    return retval;
-
   retval = map.getfield (nm);
 
   if (! auto_add && retval.is_undefined ())
@@ -1283,9 +1254,6 @@
 
       maybe_warn_invalid_field_name (key, "subsasgn");
 
-      if (error_state)
-        return retval;
-
       if (n > 1)
         {
           std::list<octave_value_list> next_idx (idx);
@@ -1302,24 +1270,20 @@
               tmp = map.contents (pkey);
             }
 
-          if (! error_state)
+          bool orig_undefined = tmp.is_undefined ();
+
+          if (orig_undefined || tmp.is_zero_by_zero ())
             {
-              bool orig_undefined = tmp.is_undefined ();
-
-              if (orig_undefined || tmp.is_zero_by_zero ())
-                {
-                  tmp = octave_value::empty_conv (next_type, rhs);
-                  tmp.make_unique (); // probably a no-op.
-                }
-              else
-                // optimization: ignore the copy still stored inside our map.
-                tmp.make_unique (1);
-
-              if (! error_state)
-                t_rhs = (orig_undefined
-                         ? tmp.undef_subsasgn (next_type, next_idx, rhs)
-                         : tmp.subsasgn (next_type, next_idx, rhs));
+              tmp = octave_value::empty_conv (next_type, rhs);
+              tmp.make_unique (); // probably a no-op.
             }
+          else
+            // optimization: ignore the copy still stored inside our map.
+            tmp.make_unique (1);
+
+          t_rhs = (orig_undefined
+                   ? tmp.undef_subsasgn (next_type, next_idx, rhs)
+                   : tmp.subsasgn (next_type, next_idx, rhs));
         }
 
       if (! error_state)
@@ -1925,14 +1889,8 @@
 
       std::string key (args(i).string_value ());
 
-      if (error_state)
-        return retval;
-
       maybe_warn_invalid_field_name (key, "struct");
 
-      if (error_state)
-        return retval;
-
       // Value may be v, { v }, or { v1, v2, ... }
       // In the first two cases, we need to create a cell array of
       // the appropriate dimensions filled with v.  In the last case,
@@ -1943,9 +1901,6 @@
         {
           const Cell c (args(i+1).cell_value ());
 
-          if (error_state)
-            return retval;
-
           if (scalar (c.dims ()))
             map.setfield (key, Cell (dims, c(0)));
           else
@@ -1953,9 +1908,6 @@
         }
       else
         map.setfield (key, Cell (dims, args(i+1)));
-
-      if (error_state)
-        return retval;
     }
 
   return octave_value (map);
@@ -2175,12 +2127,7 @@
       if (nargin == 3)
         {
           if (args(2).is_real_scalar ())
-            {
-              dim = nargin == 2 ? 0 : args(2).int_value () - 1;
-
-              if (error_state)
-                return retval;
-            }
+            dim = nargin == 2 ? 0 : args(2).int_value () - 1;
           else
             {
               error ("cell2struct: DIM must be a real scalar");
@@ -2279,28 +2226,24 @@
 
       octave_value_list fval = Fcellstr (args(1), 1);
 
-      if (! error_state)
+      Cell fcell = fval(0).cell_value ();
+
+      for (int i = 0; i < fcell.numel (); i++)
         {
-          Cell fcell = fval(0).cell_value ();
-
-          for (int i = 0; i < fcell.numel (); i++)
+          std::string key = fcell(i).string_value ();
+
+          if (m.isfield (key))
+            m.rmfield (key);
+          else
             {
-              std::string key = fcell(i).string_value ();
-
-              if (m.isfield (key))
-                m.rmfield (key);
-              else
-                {
-                  error ("rmfield: structure does not contain field %s",
-                         key.c_str ());
-
-                  break;
-                }
+              error ("rmfield: structure does not contain field %s",
+                     key.c_str ());
+
+              break;
             }
-
-          if (! error_state)
-            retval = m;
         }
+
+      retval = m;
     }
   else
     print_usage ();