mirror of
https://github.com/Open-Cascade-SAS/OCCT.git
synced 2026-08-28 22:08:25 +08:00
Coding - Remove redundant null checks before deallocation (#1077)
In C++, delete/delete[] on nullptr and free(NULL) are guaranteed no-ops. This removes redundant null-check guards before these calls across 39 files, reducing code noise without behavioral change. Also simplifies map value cleanup in BRepClass3d_SolidExplorer by using iterator reference instead of redundant hash lookups.
This commit is contained in:
@@ -835,12 +835,9 @@ void BRepClass3d_SolidExplorer::Destroy()
|
||||
NCollection_DataMap<TopoDS_Shape, void*, TopTools_ShapeMapHasher>::Iterator iter(myMapOfInter);
|
||||
for (; iter.More(); iter.Next())
|
||||
{
|
||||
void* ptr = iter.Value();
|
||||
if (ptr)
|
||||
{
|
||||
delete (IntCurvesFace_Intersector*)ptr;
|
||||
myMapOfInter.ChangeFind(iter.Key()) = nullptr;
|
||||
}
|
||||
void*& aPtr = iter.ChangeValue();
|
||||
delete (IntCurvesFace_Intersector*)aPtr;
|
||||
aPtr = nullptr;
|
||||
}
|
||||
myMapOfInter.Clear();
|
||||
}
|
||||
@@ -860,12 +857,9 @@ void BRepClass3d_SolidExplorer::InitShape(const TopoDS_Shape& S)
|
||||
NCollection_DataMap<TopoDS_Shape, void*, TopTools_ShapeMapHasher>::Iterator iter(myMapOfInter);
|
||||
for (; iter.More(); iter.Next())
|
||||
{
|
||||
void* ptr = iter.Value();
|
||||
if (ptr)
|
||||
{
|
||||
delete (IntCurvesFace_Intersector*)ptr;
|
||||
myMapOfInter.ChangeFind(iter.Key()) = nullptr;
|
||||
}
|
||||
void*& aPtr = iter.ChangeValue();
|
||||
delete (IntCurvesFace_Intersector*)aPtr;
|
||||
aPtr = nullptr;
|
||||
}
|
||||
|
||||
myMapOfInter.Clear();
|
||||
|
||||
@@ -78,10 +78,7 @@ void BRepTopAdaptor_TopolTool::Initialize(const occ::handle<Adaptor3d_Surface>&
|
||||
TopoDS_Shape s_wnt = brhs->Face();
|
||||
s_wnt.Orientation(TopAbs_FORWARD);
|
||||
myFace = TopoDS::Face(s_wnt);
|
||||
if (myFClass2d != nullptr)
|
||||
{
|
||||
delete (BRepTopAdaptor_FClass2d*)myFClass2d;
|
||||
}
|
||||
delete (BRepTopAdaptor_FClass2d*)myFClass2d;
|
||||
myFClass2d = nullptr;
|
||||
myNbSamplesU = -1;
|
||||
myS = S;
|
||||
@@ -205,11 +202,8 @@ bool BRepTopAdaptor_TopolTool::IsThePointOn(const gp_Pnt2d& P,
|
||||
|
||||
void BRepTopAdaptor_TopolTool::Destroy()
|
||||
{
|
||||
if (myFClass2d != nullptr)
|
||||
{
|
||||
delete (BRepTopAdaptor_FClass2d*)myFClass2d;
|
||||
myFClass2d = nullptr;
|
||||
}
|
||||
delete (BRepTopAdaptor_FClass2d*)myFClass2d;
|
||||
myFClass2d = nullptr;
|
||||
}
|
||||
|
||||
//=================================================================================================
|
||||
|
||||
Reference in New Issue
Block a user