diff src/ov-cell.cc @ 10670:654fbde5dceb

make cellfun's fast scalar collection mechanism public
author Jaroslav Hajek <highegg@gmail.com>
date Fri, 28 May 2010 12:28:06 +0200
parents 036bdc2d0af0
children fbd7843974fa
line wrap: on
line diff
--- a/src/ov-cell.cc	Thu May 27 20:12:51 2010 -0700
+++ b/src/ov-cell.cc	Fri May 28 12:28:06 2010 +0200
@@ -93,6 +93,34 @@
   matrix.delete_elements (idx);
 }
 
+// FIXME: this list of specializations is becoming so long that we should really ask
+// whether octave_cell should inherit from octave_base_matrix at all.
+
+template <>
+octave_value
+octave_base_matrix<Cell>::fast_elem_extract (octave_idx_type n) const
+{
+  if (n < matrix.numel ())
+    return Cell (matrix(n));
+  else
+    return octave_value ();
+}
+
+template <>
+bool
+octave_base_matrix<Cell>::fast_elem_insert (octave_idx_type n, 
+                                            const octave_value& x)
+{
+  const octave_cell *xrep = 
+    dynamic_cast<const octave_cell *> (&x.get_rep ());
+
+  bool retval = xrep && xrep->matrix.numel () == 1 && n < matrix.numel ();
+  if (retval)
+    matrix(n) = xrep->matrix(0);
+
+  return retval;
+}
+
 template class octave_base_matrix<Cell>;
 
 DEFINE_OCTAVE_ALLOCATOR (octave_cell);