From ef7b91831ea413407c2457d326b96688431caafa Mon Sep 17 00:00:00 2001 From: wolf Date: Wed, 2 Feb 2000 14:37:08 +0000 Subject: [PATCH] One optimization, one bugfix for possible problems. git-svn-id: https://svn.dealii.org/trunk@2328 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/smartpointer.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/deal.II/base/include/base/smartpointer.h b/deal.II/base/include/base/smartpointer.h index c60294ec5d..e684b6354c 100644 --- a/deal.II/base/include/base/smartpointer.h +++ b/deal.II/base/include/base/smartpointer.h @@ -152,7 +152,13 @@ SmartPointer::~SmartPointer () { template -SmartPointer & SmartPointer::operator = (T *tt) { +SmartPointer & SmartPointer::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 & SmartPointer::operator = (T *tt) { template -SmartPointer & SmartPointer::operator = (const SmartPointer& tt) { +SmartPointer & SmartPointer::operator = (const SmartPointer& 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(tt); -- 2.39.5