Salome HOME
Optimization and ease of usage. MEDCouplingMesh::buildPartRange returns this when...
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingMesh.cxx
index a9b28d58582d0efbbd550ed593c7364462c1694f..4e26cff4249d7483b6ed98ddf8a33b05c48f78be 100644 (file)
@@ -252,13 +252,26 @@ bool MEDCouplingMesh::areCompatibleForMerge(const MEDCouplingMesh *other) const
 
 /*!
  * This method is equivalent to MEDCouplingMesh::buildPart method except that here the cell ids are specified using slice \a beginCellIds \a endCellIds and \a stepCellIds.
+ * \b WARNING , there is a big difference compared to MEDCouplingMesh::buildPart method.
+ * If the input range is equal all cells in \a this, \a this is returned !
+ *
+ * \return a new ref to be managed by the caller. Warning this ref can be equal to \a this if input slice is exactly equal to the whole cells in the same order.
  *
  * \sa MEDCouplingMesh::buildPart
  */
 MEDCouplingMesh *MEDCouplingMesh::buildPartRange(int beginCellIds, int endCellIds, int stepCellIds) const throw(INTERP_KERNEL::Exception)
 {
-  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIds=DataArrayInt::Range(beginCellIds,endCellIds,stepCellIds);
-  return buildPart(cellIds->begin(),cellIds->end());
+  if(beginCellIds==0 && endCellIds==getNumberOfCells() && stepCellIds==1)
+    {
+      MEDCouplingMesh *ret(const_cast<MEDCouplingMesh *>(this));
+      ret->incrRef();
+      return ret;
+    }
+  else
+    {
+      MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIds=DataArrayInt::Range(beginCellIds,endCellIds,stepCellIds);
+      return buildPart(cellIds->begin(),cellIds->end());
+    }
 }
 
 /*!