changeset 31262:b8f4ec18e728

Allow cell input to cell() function (bug #63132) * ov-cell.cc (Fcell): Check if single input is already a cell and return it immediately if it is.
author Rik <rik@octave.org>
date Wed, 05 Oct 2022 12:03:52 -0700
parents 5f7d5934a1a9
children 449ed6f427cb
files libinterp/octave-value/ov-cell.cc
diffstat 1 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-cell.cc	Wed Oct 05 11:53:05 2022 -0700
+++ b/libinterp/octave-value/ov-cell.cc	Wed Oct 05 12:03:52 2022 -0700
@@ -1261,7 +1261,10 @@
       break;
 
     case 1:
-      get_dimensions (args(0), "cell", dims);
+      if (args(0).iscell ())
+        return args(0);  // shortcut path for input which is already a Cell
+      else
+        get_dimensions (args(0), "cell", dims);
       break;
 
     default:
@@ -1283,6 +1286,15 @@
 }
 
 /*
+
+%!test <*63132>
+%! x = {1, 3};
+%! y = cell (x);
+%! assert (x, y);
+%! x = cell (0, 3);
+%! y = cell (x);
+%! assert (x, y);
+
 ## This might work on some system someday, but for now, who has a system
 ## where a 16 yottabyte array can be allocated?  See bug #50934.
 %!error <out of memory> cell (1e24, 1)