diff liboctave/Array.cc @ 9678:c929f09457b7

rewrite num2cell for speed-up + a few associated fixes
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 01 Oct 2009 14:07:06 +0200
parents 3fc7272937ce
children aea3a3a950e1
line wrap: on
line diff
--- a/liboctave/Array.cc	Thu Oct 01 08:34:13 2009 +0200
+++ b/liboctave/Array.cc	Thu Oct 01 14:07:06 2009 +0200
@@ -592,6 +592,8 @@
   // Need this array to check for identical elements in permutation array.
   OCTAVE_LOCAL_BUFFER_INIT (bool, checked, perm_vec_len, false);
 
+  bool identity = true;
+
   // Find dimension vector of permuted array.
   for (int i = 0; i < perm_vec_len; i++)
     {
@@ -614,11 +616,17 @@
 	  return retval;
 	}
       else
-	checked[perm_elt] = true;
+        {
+          checked[perm_elt] = true;
+          identity = identity && perm_elt == i;
+        }
 
       dv_new(i) = dv(perm_elt);
     }
 
+  if (identity)
+    return *this;
+
   if (inv)
     {
       for (int i = 0; i < perm_vec_len; i++)