------- Comment #6 from pault at gcc dot gnu dot org  2008-11-30 19:53 -------
Index: libgfortran/generated/reshape_r4.c
===================================================================
--- libgfortran/generated/reshape_r4.c  (revision 142291)
+++ libgfortran/generated/reshape_r4.c  (working copy)
@@ -81,7 +81,7 @@
   const GFC_REAL_4 *src;
   int n;
   int dim;
-  int sempty, pempty, shape_empty;
+  int sempty, pempty, shape_empty, contiguous_data;
   index_type shape_data[GFC_MAX_DIMENSIONS];

   rdim = shape->dim[0].ubound - shape->dim[0].lbound + 1;
@@ -100,6 +100,24 @@
       }
     }

+  contiguous_data = 1;
+
+  for (n = 0; n < GFC_DESCRIPTOR_RANK(source); n++)
+    {
+      if (n == 0)
+      {
+        if (source->dim[n].stride != 1)
+         contiguous_data = 0;
+      }
+      else if (contiguous_data)
+      {
+       int del = source->dim[n-1].ubound - source->dim[n-1].lbound + 1;
+        if (source->dim[n].stride != del)
+         contiguous_data = 0;  
+      }
+    }
+   st_printf ("data %d\n", (int)contiguous_data);
+
   if (ret->data == NULL)
     {
       rs = 1;
@@ -112,6 +130,11 @@
          rs *= rex;
        }
       ret->offset = 0;
+      if (contiguous_data)
+      {
+       ret->data = source->data;
+       return;
+      }
       ret->data = internal_malloc_size ( rs * sizeof (GFC_REAL_4));
       ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
     }

Was an experiment to see if an improvement to reshape could easily be
implemented in the library.  It fails completely, of course, because the source
is freed!  This does show that a flag in the descriptor to say that 'this'
cannot be freed would be a boon.

Paul


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32512

Reply via email to