]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
One optimization, one bugfix for possible problems.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 2 Feb 2000 14:37:08 +0000 (14:37 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 2 Feb 2000 14:37:08 +0000 (14:37 +0000)
git-svn-id: https://svn.dealii.org/trunk@2328 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/smartpointer.h

index c60294ec5deb00f8c66ccdf5f1e5a3c853f24283..e684b6354ce94e08f28df28e65b5d8c83c692bef 100644 (file)
@@ -152,7 +152,13 @@ SmartPointer<T>::~SmartPointer () {
 
 
 template <typename T>
-SmartPointer<T> & SmartPointer<T>::operator = (T *tt) {
+SmartPointer<T> & SmartPointer<T>::operator = (T *tt)
+{
+                                  // optimize if no real action is
+                                  // requested
+  if (t == tt)
+    return *this;
+  
   if (t)
     t->unsubscribe();
   t = tt;
@@ -163,7 +169,14 @@ SmartPointer<T> & SmartPointer<T>::operator = (T *tt) {
 
 
 template <typename T>
-SmartPointer<T> & SmartPointer<T>::operator = (const SmartPointer<T>& tt) {
+SmartPointer<T> & SmartPointer<T>::operator = (const SmartPointer<T>& tt)
+{
+                                  // if objects on the left and right
+                                  // hand side of the operator= are
+                                  // the same, then this is a no-op
+  if (&tt == this)
+    return *this;
+  
   if (t)
     t->unsubscribe();
   t = static_cast<T*>(tt);

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.