From 3884dcd0d85d115509101d3ccce7a31f330ac7df Mon Sep 17 00:00:00 2001
From: Jonathan Lambrechts <jonathan.lambrechts@uclouvain.be>
Date: Mon, 3 Jan 2011 13:20:57 +0000
Subject: [PATCH] fullMatrix : copy, invert and operator =  do not re-allocate
 memory if the size is correct (so that they can be used on proxies)

---
 Numeric/fullMatrix.h | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/Numeric/fullMatrix.h b/Numeric/fullMatrix.h
index 6bad73638e..9ccfc9d925 100644
--- a/Numeric/fullMatrix.h
+++ b/Numeric/fullMatrix.h
@@ -265,16 +265,18 @@ class fullMatrix
   fullMatrix<scalar> & operator = (const fullMatrix<scalar> &other)
   {
     if(this != &other){
-      _r = other._r; 
-      _c = other._c;
-      if (_data && _own_data) delete[] _data;
-      if ((_r == 0) || (_c == 0))
-        _data=0;
-      else{
-        _data = new scalar[_r * _c];
-        _own_data=true;
-        for(int i = 0; i < _r * _c; ++i) _data[i] = other._data[i];
+      if (_r != other._r || _c != other._c) {
+        _r = other._r; 
+        _c = other._c;
+        if (_data && _own_data) delete[] _data;
+        if ((_r == 0) || (_c == 0))
+          _data=0;
+        else{
+          _data = new scalar[_r * _c];
+          _own_data=true;
+        }
       }
+      for(int i = 0; i < _r * _c; ++i) _data[i] = other._data[i];
     }
     return *this;
   }
@@ -311,12 +313,14 @@ class fullMatrix
   }
   void copy(const fullMatrix<scalar> &a)
   {
-    if(_data && _own_data)
-      delete [] _data;
-    _r = a._r;
-    _c = a._c;
-    _data = new scalar[_r * _c];
-    _own_data = true;
+    if (_r != a._r || _c != a._c) {
+      if(_data && _own_data)
+        delete [] _data;
+      _r = a._r;
+      _c = a._c;
+      _data = new scalar[_r * _c];
+      _own_data = true;
+    }
     setAll(a);
   }
   void mult_naive(const fullMatrix<scalar> &b, fullMatrix<scalar> &c) const
-- 
GitLab