[Libreoffice] Remove NULL checks from delete

Stephan Bergmann sbergman at redhat.com
Mon Sep 19 13:52:44 PDT 2011


On 09/19/2011 08:58 PM, Thomas Arnhold wrote:
> 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?

By the way, using the below regexps (best run in a C locale) should find 
even more instances, and should avoid false positives of the form "if 
(foo) delete bar;" or (unlikely) "#if (foo) \n delete foo;":

> foreach (@ARGV) {
>   my $file = $_;
>   open(FH, "<$file");
>   my $data = "";
>   while (<FH>) { $data .= $_; }
>   close(FH);
>   while ($data =~ /((?<!#)\s*\bif\s*\(\s*(\w+)\s*\)\s*delete\s+\2\s*;)/g) {
>     print "found <$1>\n";
>   }
>   while ($data =~ /((?<!#)\s*\bif\s*\(\s*(\w+)\s*\)\s*{\s*delete\s+\2\s*;\s*})/g) {
>     print "found <$1>\n";
>   }
> }

(The outer parentheses are only there for print "found <$1>\n" to work 
-- no idea how Perl makes available the complete match without that 
hack...  The leading "(?<!#)\s*" should really read "(?<!#\s*)", but 
then Perl complains that "Variable length lookbehind [is] not implemented.")

-Stephan


More information about the LibreOffice mailing list