From: geay Date: Thu, 20 Feb 2014 15:51:29 +0000 (+0100) Subject: improve perf of convertToPolyTypes X-Git-Tag: V7_4_0a1~41 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3a8a33872726a1f3aa0cf22149006e664c331ab3;p=modules%2Fmed.git improve perf of convertToPolyTypes --- diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index d97d8137a..fa1da10ee 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -1015,7 +1015,7 @@ void MEDCouplingUMesh::convertToPolyTypes(const int *cellIdsToConvertBg, const i int dim=getMeshDimension(); if(dim<2 || dim>3) throw INTERP_KERNEL::Exception("Invalid mesh dimension : must be 2 or 3 !"); - int nbOfCells=getNumberOfCells(); + int nbOfCells(getNumberOfCells()); if(dim==2) { const int *connIndex=_nodal_connec_index->getConstPointer(); @@ -1044,43 +1044,48 @@ void MEDCouplingUMesh::convertToPolyTypes(const int *cellIdsToConvertBg, const i int connIndexLgth=_nodal_connec_index->getNbOfElems(); const int *connOld=_nodal_connec->getConstPointer(); int connOldLgth=_nodal_connec->getNbOfElems(); - std::vector connNew(connOld,connOld+connOldLgth); + MEDCouplingAutoRefCountObjectPtr connNew(DataArrayInt::New()),connNewI(DataArrayInt::New()); connNew->alloc(0,1); connNewI->alloc(1,1); connNewI->setIJ(0,0,0); + std::vector toBeDone(nbOfCells,false); for(const int *iter=cellIdsToConvertBg;iter!=cellIdsToConvertEnd;iter++) { if(*iter>=0 && *iter(),delta)); - connNew.insert(connNew.begin()+posP1,tmp+lgthOld,tmp+newLgth); - std::copy(tmp,tmp+lgthOld,connNew.begin()+pos+1); + std::size_t newLgth(std::distance(tmp,work)-1);//-1 for last -1 + connNew->pushBackValsSilent(tmp,tmp+newLgth); + connNewI->pushBackSilent(connNewI->back()+(int)newLgth); delete [] tmp; } else { - std::ostringstream oss; oss << "MEDCouplingUMesh::convertToPolyTypes : On rank #" << std::distance(cellIdsToConvertBg,iter) << " value is " << *iter << " which is not"; - oss << " in range [0," << nbOfCells << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + connNew->pushBackValsSilent(connOld+pos,connOld+posP1); + connNewI->pushBackSilent(connNewI->back()+posP1-pos); } } - _nodal_connec->alloc((int)connNew.size(),1); - int *newConnPtr=_nodal_connec->getPointer(); - std::copy(connNew.begin(),connNew.end(),newConnPtr); + setConnectivity(connNew,connNewI,false);//false because computeTypes called just behind. } computeTypes(); }