diff src/ov.cc @ 10325:8b3cfc1288e2

implement lazy index conversions
author Jaroslav Hajek <highegg@gmail.com>
date Tue, 16 Feb 2010 15:28:53 +0100
parents 57a59eae83cc
children 12884915a8e4
line wrap: on
line diff
--- a/src/ov.cc	Mon Feb 15 08:55:46 2010 +0100
+++ b/src/ov.cc	Tue Feb 16 15:28:53 2010 +0100
@@ -74,6 +74,7 @@
 #include "ov-fcn-inline.h"
 #include "ov-typeinfo.h"
 #include "ov-null-mat.h"
+#include "ov-lazy-idx.h"
 
 #include "defun.h"
 #include "error.h"
@@ -1044,7 +1045,7 @@
   maybe_mutate ();
 }
 
-octave_value::octave_value (const idx_vector& idx)
+octave_value::octave_value (const idx_vector& idx, bool lazy)
   : rep ()
 {
   double scalar;
@@ -1053,6 +1054,21 @@
   boolNDArray mask;
   idx_vector::idx_class_type idx_class;
 
+  if (lazy)
+    {
+      // Only make lazy indices out of ranges and index vectors.
+      switch (idx.idx_class ())
+        {
+        case idx_vector::class_range:
+        case idx_vector::class_vector:
+          rep = new octave_lazy_index (idx);
+          maybe_mutate ();
+          return;
+        default:
+          break;
+        }
+    }
+
   idx.unconvert (idx_class, scalar, range, array, mask);
 
   switch (idx_class)
@@ -1135,8 +1151,7 @@
 octave_base_value *
 octave_value::clone (void) const
 {
-  panic_impossible ();
-  return 0;
+  return rep->clone ();
 }
 
 void
@@ -2653,6 +2668,7 @@
   octave_null_matrix::register_type ();
   octave_null_str::register_type ();
   octave_null_sq_str::register_type ();
+  octave_lazy_index::register_type ();
 }
 
 #if 0