changeset 9058:2da105bf2507

remove redundant checks from Array<T>::index
author Jaroslav Hajek <highegg@gmail.com>
date Sun, 29 Mar 2009 18:09:44 +0200
parents 8b263623d0f3
children eabdfcc977f1
files liboctave/Array.cc liboctave/ChangeLog
diffstat 2 files changed, 60 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/Array.cc	Sun Mar 29 09:05:44 2009 +0200
+++ b/liboctave/Array.cc	Sun Mar 29 18:09:44 2009 +0200
@@ -1272,24 +1272,20 @@
           n = numel ();
         }
 
-      // If the resizing was ambiguous, resize has already griped.
-      if (nx == n)
+      if (i.is_colon ())
         {
-          if (i.is_colon ())
-            {
-              // A(:) = X makes a full fill or a shallow copy.
-              if (rhl == 1)
-                fill (rhs(0));
-              else
-                *this = rhs.reshape (dimensions);
-            }
+          // A(:) = X makes a full fill or a shallow copy.
+          if (rhl == 1)
+            fill (rhs(0));
           else
-            {
-              if (rhl == 1)
-                i.fill (rhs(0), n, fortran_vec ());
-              else
-                i.assign (rhs.data (), n, fortran_vec ());
-            }
+            *this = rhs.reshape (dimensions);
+        }
+      else
+        {
+          if (rhl == 1)
+            i.fill (rhs(0), n, fortran_vec ());
+          else
+            i.assign (rhs.data (), n, fortran_vec ());
         }
     }
   else
@@ -1345,51 +1341,45 @@
           dv = dimensions;
         }
 
-      // If the resizing was invalid, resize has already griped.
-      if (dv == rdv)
+      if (i.is_colon () && j.is_colon ())
+        {
+          // A(:,:) = X makes a full fill or a shallow copy
+          if (isfill)
+            fill (rhs(0));
+          else
+            *this = rhs.reshape (dimensions);
+        }
+      else
         {
-          if (i.is_colon () && j.is_colon ())
+          // The actual work.
+          octave_idx_type n = numel (), r = dv (0), c = dv (1);
+          idx_vector ii (i);
+
+          const T* src = rhs.data ();
+          T *dest = fortran_vec ();
+
+          // Try reduction first.
+          if (ii.maybe_reduce (r, j, c))
             {
-              // A(:,:) = X makes a full fill or a shallow copy
               if (isfill)
-                fill (rhs(0));
+                ii.fill (*src, n, dest);
               else
-                *this = rhs.reshape (dimensions);
+                ii.assign (src, n, dest);
             }
           else
             {
-              // The actual work.
-              octave_idx_type n = numel (), r = dv (0), c = dv (1);
-              idx_vector ii (i);
-
-              const T* src = rhs.data ();
-              T *dest = fortran_vec ();
-
-              // Try reduction first.
-              if (ii.maybe_reduce (r, j, c))
+              if (isfill)
                 {
-                  if (isfill)
-                    ii.fill (*src, n, dest);
-                  else
-                    ii.assign (src, n, dest);
+                  for (octave_idx_type k = 0; k < jl; k++)
+                    i.fill (*src, r, dest + r * j.xelem (k));
                 }
               else
                 {
-                  if (isfill)
-                    {
-                      for (octave_idx_type k = 0; k < jl; k++)
-                        i.fill (*src, r, dest + r * j.xelem (k));
-                    }
-                  else
-                    {
-                      for (octave_idx_type k = 0; k < jl; k++)
-                        src += i.assign (src, r, dest + r * j.xelem (k));
-                    }
+                  for (octave_idx_type k = 0; k < jl; k++)
+                    src += i.assign (src, r, dest + r * j.xelem (k));
                 }
             }
-          
         }
-
     }
   else
     gripe_assignment_dimension_mismatch ();
@@ -1456,30 +1446,26 @@
               chop_trailing_singletons ();
             }
 
-          // If the resizing was invalid, resize has already griped.
-          if (dv == rdv)
+          if (all_colons)
             {
-              if (all_colons)
-                {
-                  // A(:,:,...,:) = X makes a full fill or a shallow copy.
-                  if (isfill)
-                    fill (rhs(0));
-                  else
-                    *this = rhs.reshape (dimensions);
-                }
+              // A(:,:,...,:) = X makes a full fill or a shallow copy.
+              if (isfill)
+                fill (rhs(0));
               else
-                {
-                  // Do the actual work.
-
-                  // Prepare for recursive indexing
-                  rec_index_helper rh (dv, ia);
-
-                  // Do it.
-                  if (isfill)
-                    rh.fill (rhs(0), fortran_vec ());
-                  else
-                    rh.assign (rhs.data (), fortran_vec ());
-                }
+                *this = rhs.reshape (dimensions);
+            }
+          else
+            {
+              // Do the actual work.
+
+              // Prepare for recursive indexing
+              rec_index_helper rh (dv, ia);
+
+              // Do it.
+              if (isfill)
+                rh.fill (rhs(0), fortran_vec ());
+              else
+                rh.assign (rhs.data (), fortran_vec ());
             }
         }
       else 
--- a/liboctave/ChangeLog	Sun Mar 29 09:05:44 2009 +0200
+++ b/liboctave/ChangeLog	Sun Mar 29 18:09:44 2009 +0200
@@ -1,3 +1,8 @@
+2009-03-29  Jaroslav Hajek  <highegg@gmail.com>
+
+	* Array.cc (Array<T>::assign): Remove redundant checks after invalid
+	resize.
+
 2009-03-26  Jaroslav Hajek  <highegg@gmail.com>
 
 	* Array.cc (Array<T>::find): Reshape result for Matlab compatibility.