diff liboctave/Array.h @ 9556:948795dc1974

make a few Array methods inline
author Jaroslav Hajek <highegg@gmail.com>
date Sun, 23 Aug 2009 22:00:03 +0200
parents 1beb23d2b892
children 3fc7272937ce
line wrap: on
line diff
--- a/liboctave/Array.h	Sun Aug 23 05:57:51 2009 +0200
+++ b/liboctave/Array.h	Sun Aug 23 22:00:03 2009 +0200
@@ -98,7 +98,15 @@
 
 public:
 
-  void make_unique (void);
+  void make_unique (void)
+    {
+      if (rep->count > 1)
+        {
+          --rep->count;
+          rep = new ArrayRep (slice_data, slice_len, true);
+          slice_data = rep->data;
+        }
+    }
 
   typedef T element_type;
 
@@ -233,9 +241,29 @@
 
   Array (const Array<T>& a, const dim_vector& dv);
 
-  virtual ~Array (void);
+  ~Array (void)
+    {
+      if (--rep->count <= 0)
+        delete rep;
+    }
 
-  Array<T>& operator = (const Array<T>& a);
+  Array<T>& operator = (const Array<T>& a)
+    {
+      if (this != &a)
+        {
+          if (--rep->count <= 0)
+            delete rep;
+
+          rep = a.rep;
+          rep->count++;
+
+          dimensions = a.dimensions;
+          slice_data = a.slice_data;
+          slice_len = a.slice_len;
+        }
+
+      return *this;
+    }
 
   void fill (const T& val); 
   void clear (void);