Hi,
I've recently seen some changes, which removed unnecessary NULL checks
for delete commands with the form:
- if (pTextPContext)
- delete pTextPContext;
+ delete pTextPContext;
Codebase is full with these. I've attached a little perl script which
should solve this conversion. I've attached a sample for the vcl dir.
Any objections?
Thomas
#!/usr/bin/perl
# run:
# find /path/to/libo -name *.cxx | xargs perl replaceDelete.pl
# process multi file targets
foreach (@ARGV) {
my $file = $_;
my $data = "";
# grep file to $data
open(fh, "<$file");
while (<fh>) { $data .= $_; }
close(fh);
# replaces unnecessary if checks for delete, example:
#
# - if (pTextPContext)
# - delete pTextPContext;
# + delete pTextPContext;
# check for: if ( testString ) delete testString;
while ($data =~ /if \(\s*([A-Za-z]+)\s*\)\s*\n\s*delete\s+[A-Za-z]+\s*\;/gs) {
print "found: $1\n";
# use intendation of if statement
$data =~ s/(\n\s*)if \(\s*$1\s*\)\s*\n\s+(delete\s+$1\s*\;)/$1$2/gs;
}
# write file
open(fh, ">$file");
print fh $data;
close(fh);
}
diff --git a/vcl/aqua/source/window/salframe.cxx b/vcl/aqua/source/window/salframe.cxx
index 56eff66..74e0891 100644
--- a/vcl/aqua/source/window/salframe.cxx
+++ b/vcl/aqua/source/window/salframe.cxx
@@ -127,8 +127,7 @@ AquaSalFrame::~AquaSalFrame()
if( this == s_pCaptureFrame )
s_pCaptureFrame = NULL;
- if ( mpGraphics )
- delete mpGraphics;
+ delete mpGraphics;
if( mpDockMenuEntry )
// life cycle comment: the menu has ownership of the item, so no release
diff --git a/vcl/ios/source/window/salframe.cxx b/vcl/ios/source/window/salframe.cxx
index f0745ed..73d3e5b 100644
--- a/vcl/ios/source/window/salframe.cxx
+++ b/vcl/ios/source/window/salframe.cxx
@@ -106,8 +106,7 @@ IosSalFrame::~IosSalFrame()
if( this == s_pCaptureFrame )
s_pCaptureFrame = NULL;
- if ( mpGraphics )
- delete mpGraphics;
+ delete mpGraphics;
if ( mpView ) {
[mpView release];
diff --git a/vcl/source/app/dbggui.cxx b/vcl/source/app/dbggui.cxx
index 6e76706..468e7c8 100755
--- a/vcl/source/app/dbggui.cxx
+++ b/vcl/source/app/dbggui.cxx
@@ -1998,8 +1998,7 @@ void DbgGUIDeInit()
DbgSetAbort( NULL );
DbgWindow* pDbgWindow = ImplGetSVData()->maWinData.mpDbgWin;
- if ( pDbgWindow )
- delete pDbgWindow;
+ delete pDbgWindow;
}
// -----------------------------------------------------------------------
diff --git a/vcl/source/app/settings.cxx b/vcl/source/app/settings.cxx
index eec8ba5..ff57877 100644
--- a/vcl/source/app/settings.cxx
+++ b/vcl/source/app/settings.cxx
@@ -1556,10 +1556,8 @@ ImplAllSettingsData::ImplAllSettingsData( const ImplAllSettingsData& rData ) :
ImplAllSettingsData::~ImplAllSettingsData()
{
- if ( mpLocaleDataWrapper )
- delete mpLocaleDataWrapper;
- if ( mpUILocaleDataWrapper )
- delete mpUILocaleDataWrapper;
+ delete mpLocaleDataWrapper;
+ delete mpUILocaleDataWrapper;
if ( mpI18nHelper )
delete mpI18nHelper;
if ( mpUII18nHelper )
diff --git a/vcl/source/control/edit.cxx b/vcl/source/control/edit.cxx
index e36cdaf..2cd5f47 100644
--- a/vcl/source/control/edit.cxx
+++ b/vcl/source/control/edit.cxx
@@ -253,8 +253,7 @@ Edit::~Edit()
delete mpIMEInfos;
- if ( mpUpdateDataTimer )
- delete mpUpdateDataTimer;
+ delete mpUpdateDataTimer;
if ( mxDnDListener.is() )
{
diff --git a/vcl/source/control/menubtn.cxx b/vcl/source/control/menubtn.cxx
index 13513f6..2e1ad53 100644
--- a/vcl/source/control/menubtn.cxx
+++ b/vcl/source/control/menubtn.cxx
@@ -133,10 +133,8 @@ void MenuButton::ImplLoadRes( const ResId& rResId )
MenuButton::~MenuButton()
{
- if ( mpMenuTimer )
- delete mpMenuTimer;
- if ( mpOwnMenu )
- delete mpOwnMenu;
+ delete mpMenuTimer;
+ delete mpOwnMenu;
}
// -----------------------------------------------------------------------
diff --git a/vcl/source/gdi/print.cxx b/vcl/source/gdi/print.cxx
index 440da9c..6a47815 100644
--- a/vcl/source/gdi/print.cxx
+++ b/vcl/source/gdi/print.cxx
@@ -722,8 +722,7 @@ Printer::~Printer()
ImplReleaseGraphics();
if ( mpInfoPrinter )
ImplGetSVData()->mpDefInst->DestroyInfoPrinter( mpInfoPrinter );
- if ( mpDisplayDev )
- delete mpDisplayDev;
+ delete mpDisplayDev;
else
{
// OutputDevice-Dtor versucht das gleiche, deshalb muss hier
diff --git a/vcl/source/gdi/regband.cxx b/vcl/source/gdi/regband.cxx
index 1cec295..b091783 100644
--- a/vcl/source/gdi/regband.cxx
+++ b/vcl/source/gdi/regband.cxx
@@ -201,8 +201,7 @@ void ImplRegionBand::ProcessPoints()
}
// remove last element if necessary
- if ( pRegionBandPoint )
- delete pRegionBandPoint;
+ delete pRegionBandPoint;
// list is now empty
mpFirstBandPoint = NULL;
diff --git a/vcl/source/window/accmgr.cxx b/vcl/source/window/accmgr.cxx
index 43c78d5..a14530a 100644
--- a/vcl/source/window/accmgr.cxx
+++ b/vcl/source/window/accmgr.cxx
@@ -43,10 +43,8 @@ DBG_NAMEEX( Accelerator )
ImplAccelManager::~ImplAccelManager()
{
- if ( mpAccelList )
- delete mpAccelList;
- if ( mpSequenceList )
- delete mpSequenceList;
+ delete mpAccelList;
+ delete mpSequenceList;
}
// -----------------------------------------------------------------------
diff --git a/vcl/source/window/brdwin.cxx b/vcl/source/window/brdwin.cxx
index d048b3a..bf25f34 100644
--- a/vcl/source/window/brdwin.cxx
+++ b/vcl/source/window/brdwin.cxx
@@ -1438,10 +1438,8 @@ ImplStdBorderWindowView::ImplStdBorderWindowView( ImplBorderWindow* pBorderWindo
ImplStdBorderWindowView::~ImplStdBorderWindowView()
{
- if ( mpATitleVirDev )
- delete mpATitleVirDev;
- if ( mpDTitleVirDev )
- delete mpDTitleVirDev;
+ delete mpATitleVirDev;
+ delete mpDTitleVirDev;
}
// -----------------------------------------------------------------------
diff --git a/vcl/source/window/msgbox.cxx b/vcl/source/window/msgbox.cxx
index e27cefe..9b000c9 100644
--- a/vcl/source/window/msgbox.cxx
+++ b/vcl/source/window/msgbox.cxx
@@ -258,8 +258,7 @@ void MessBox::ImplPosControls()
WinBits nWinStyle = WB_LEFT | WB_WORDBREAK | WB_NOLABEL | WB_INFO;
sal_uInt16 nTextStyle = TEXT_DRAW_MULTILINE | TEXT_DRAW_TOP | TEXT_DRAW_LEFT;
- if ( mpFixedText )
- delete mpFixedText;
+ delete mpFixedText;
if ( mpFixedImage )
{
delete mpFixedImage;
diff --git a/vcl/source/window/splitwin.cxx b/vcl/source/window/splitwin.cxx
index 8ea0246..9488438 100644
--- a/vcl/source/window/splitwin.cxx
+++ b/vcl/source/window/splitwin.cxx
@@ -2633,8 +2633,7 @@ void SplitWindow::Tracking( const TrackingEvent& rTEvt )
if ( rTEvt.IsTrackingEnded() )
{
- if ( mpLastSizes )
- delete mpLastSizes;
+ delete mpLastSizes;
mpLastSizes = NULL;
mpSplitSet = NULL;
mnMouseOff = 0;
diff --git a/vcl/source/window/tabdlg.cxx b/vcl/source/window/tabdlg.cxx
index 32e8a0d..beb02a1 100644
--- a/vcl/source/window/tabdlg.cxx
+++ b/vcl/source/window/tabdlg.cxx
@@ -239,8 +239,7 @@ TabDialog::TabDialog( Window* pParent, const ResId& rResId ) :
TabDialog::~TabDialog()
{
- if ( mpFixedLine )
- delete mpFixedLine;
+ delete mpFixedLine;
}
// -----------------------------------------------------------------------
diff --git a/vcl/source/window/toolbox.cxx b/vcl/source/window/toolbox.cxx
index 742d821..d9c9123 100644
--- a/vcl/source/window/toolbox.cxx
+++ b/vcl/source/window/toolbox.cxx
@@ -1804,8 +1804,7 @@ ToolBox::~ToolBox()
delete mpData;
// FloatSizeAry gegebenenfalls loeschen
- if ( mpFloatSizeAry )
- delete mpFloatSizeAry;
+ delete mpFloatSizeAry;
// Wenn keine ToolBox-Referenzen mehr auf die Listen bestehen, dann
// Listen mit wegloeschen
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index d0646e0..89e5b0b 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -1899,8 +1899,7 @@ sal_Bool Window::ImplSetClipFlagChilds( sal_Bool bSysObjOnlySmaller )
bUpdate = sal_False;
}
- if ( pOldRegion )
- delete pOldRegion;
+ delete pOldRegion;
}
else
{
@@ -2459,8 +2458,7 @@ void Window::ImplCallPaint( const Region* pRegion, sal_uInt16 nPaintFlags )
if( !aSelectionRect.IsEmpty() )
DrawSelectionBackground( aSelectionRect, 3, sal_False, sal_True, sal_False );
- if ( pChildRegion )
- delete pChildRegion;
+ delete pChildRegion;
}
// -----------------------------------------------------------------------
@@ -3484,10 +3482,8 @@ void Window::ImplPosSizeWindow( long nX, long nY,
mpWindowImpl->mpSysObj->SetPosSize( mnOutOffX, mnOutOffY, mnOutWidth, mnOutHeight );
}
- if ( pOverlapRegion )
- delete pOverlapRegion;
- if ( pOldRegion )
- delete pOldRegion;
+ delete pOverlapRegion;
+ delete pOldRegion;
}
// -----------------------------------------------------------------------
diff --git a/vcl/unx/generic/glyphs/gcach_ftyp.cxx b/vcl/unx/generic/glyphs/gcach_ftyp.cxx
index ffa4aa3..02b5c1f 100644
--- a/vcl/unx/generic/glyphs/gcach_ftyp.cxx
+++ b/vcl/unx/generic/glyphs/gcach_ftyp.cxx
@@ -362,8 +362,7 @@ FtFontInfo::~FtFontInfo()
delete mpChar2Glyph;
delete mpGlyph2Char;
#ifdef ENABLE_GRAPHITE
- if (mpGraphiteFace)
- delete mpGraphiteFace;
+ delete mpGraphiteFace;
#endif
}
diff --git a/vcl/win/source/gdi/salgdi.cxx b/vcl/win/source/gdi/salgdi.cxx
index 3c0e828..ee34758 100644
--- a/vcl/win/source/gdi/salgdi.cxx
+++ b/vcl/win/source/gdi/salgdi.cxx
@@ -785,14 +785,11 @@ WinSalGraphics::~WinSalGraphics()
if ( mpStdClipRgnData )
delete [] mpStdClipRgnData;
- if ( mpLogFont )
- delete mpLogFont;
+ delete mpLogFont;
- if ( mpFontCharSets )
- delete mpFontCharSets;
+ delete mpFontCharSets;
- if ( mpFontKernPairs )
- delete mpFontKernPairs;
+ delete mpFontKernPairs;
}
// -----------------------------------------------------------------------
diff --git a/vcl/win/source/window/salobj.cxx b/vcl/win/source/window/salobj.cxx
index f79ad89..6300909 100644
--- a/vcl/win/source/window/salobj.cxx
+++ b/vcl/win/source/window/salobj.cxx
@@ -656,8 +656,7 @@ WinSalObject::~WinSalObject()
}
// Cache-Daten zerstoeren
- if ( mpStdClipRgnData )
- delete mpStdClipRgnData;
+ delete mpStdClipRgnData;
HWND hWndParent = ::GetParent( mhWnd );
_______________________________________________
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice