[PATCH] Accelerate Perl installer builder

Jan Darmochwal jdarmochwal at gmx.de
Thu Feb 3 03:30:37 PST 2011


speed up get_all_items_from_script
---
 solenv/bin/modules/installer/remover.pm     |    4 +-
 solenv/bin/modules/installer/setupscript.pm |  127 +++++++++++---------------
 2 files changed, 56 insertions(+), 75 deletions(-)

diff --git a/solenv/bin/modules/installer/remover.pm b/solenv/bin/modules/installer/remover.pm
index 75af6e8..2c039ec 100644
--- a/solenv/bin/modules/installer/remover.pm
+++ b/solenv/bin/modules/installer/remover.pm
@@ -37,8 +37,8 @@ sub remove_leading_and_ending_whitespaces
 {
     my ( $stringref ) = @_;
 
-    $$stringref =~ s/^\s*//;
-    $$stringref =~ s/\s*$//;	
+    $$stringref =~ s/^\s+//;
+    $$stringref =~ s/\s+$//;
 }
 
 sub remove_leading_and_ending_quotationmarks
diff --git a/solenv/bin/modules/installer/setupscript.pm b/solenv/bin/modules/installer/setupscript.pm
index 7d3f77f..4e2fbf6 100644
--- a/solenv/bin/modules/installer/setupscript.pm
+++ b/solenv/bin/modules/installer/setupscript.pm
@@ -303,94 +303,75 @@ sub get_all_items_from_script
     my ($scriptref, $searchitem) = @_;
 
     my @allitemarray = ();
-    
-    my ($itemkey, $itemvalue, $valuecounter);
+
+    my ($itemkey, $itemvalue);
 
     for ( my $i = 0; $i <= $#{$scriptref}; $i++ )
     {
         my $line = ${$scriptref}[$i];
-        
-        if ( $line =~ /^\s*\Q$searchitem\E\s+(\S+)\s*$/ )
+
+        next unless ($line =~ /^\s*\Q$searchitem\E\s+(\S+)\s*$/);
+        my $gid = $1;
+
+        my %oneitemhash = ();
+        my $ismultilang = 0;
+
+        $oneitemhash{'gid'} = $gid;
+
+        while (!( $line =~ /^\s*End\s*$/ ))
         {
-            my $gid = $1;
-            my $counter = $i + 1;
-            
-            my %oneitemhash = ();
-            my $ismultilang = 0;
-            
-            $oneitemhash{'gid'} = $gid;			
-                        
-            while  (!( $line =~ /^\s*End\s*$/ ))
+            if ( $i >= $#{$scriptref} ) {
+                installer::exiter::exit_program("Invalid setup script file. End of file reached before 'End' line of '$searchitem' section.", "get_all_items_from_script");
+            }
+            $line = ${$scriptref}[++$i];
+
+            if ( $line =~ /^\s*(.+?)\=\s*(.+?)\;\s*$/ ) # only oneliner!
             {
-                if ( $counter > $#{$scriptref} ) {
-                    installer::exiter::exit_program("Invalid setup script file. End of file reached before 'End' line of '$searchitem' section.", "get_all_items_from_script");
-                }
-                $line = ${$scriptref}[$counter];
-                $counter++;
+                $itemkey = $1;
+                $itemvalue = $2;
 
-                if ( $line =~ /^\s*(.+?)\s*\=\s*(.+?)\s*\;\s*$/ )	# only oneliner!
-                {
-                    $itemkey = $1;
-                    $itemvalue = $2;
+                $itemkey =~ s/\s+$//;
+                $itemvalue =~ s/\s+$//;
 
-                    installer::remover::remove_leading_and_ending_quotationmarks(\$itemvalue);
-                    $itemvalue =~ s/\s*$//; # removing ending whitespaces. Could be introduced by empty variables.
+                installer::remover::remove_leading_and_ending_quotationmarks(\$itemvalue);
 
-                    $oneitemhash{$itemkey} = $itemvalue;
+                $oneitemhash{$itemkey} = $itemvalue;
 
-                    if ( $itemkey =~ /^\s*\S+\s+\(\S+\)\s*$/ )
-                    {
-                        $ismultilang = 1;			
-                    }
-                }
-                else
+                $ismultilang ||= $itemkey =~ /^\S+\s+\(\S+\)$/;
+            }
+            elsif (($searchitem eq "Module") &&
+                   ($line =~ /^\s*.+?\s*\=\s*\(/) &&
+                   (!($line =~ /\)\;\s*$/)))	# more than one line, for instance files at modules!
+            {
+                $line =~ /^\s*(.+?)\s*\=\s*(.+?)\s*$/; 	# the first line
+                $itemkey = $1;
+                $itemvalue = $2;
+
+                # collecting the complete itemvalue
+                do
                 {
-                    if ( $searchitem eq "Module" ) # more than one line, for instance files at modules!
-                    {
-                        if (( $line =~ /^\s*(.+?)\s*\=\s*\(/ ) && (!($line =~ /\)\;\s*$ / )))	
-                        {
-                            if ( $line =~ /^\s*(.+?)\s*\=\s*(.+)/ )	# the first line
-                            {
-                                $itemkey = $1;
-                                $itemvalue = $2;
-                                $itemvalue =~ s/\s*$//;
-                            }
-
-                            # collecting the complete itemvalue
-
-                            $valuecounter = $counter;
-                            $line = ${$scriptref}[$valuecounter];							
-                            installer::remover::remove_leading_and_ending_whitespaces(\$line);
-                            $itemvalue = $itemvalue . $line;
-                            
-                            while (!( $line =~ /\)\;\s*$/ ))
-                            {
-                                $valuecounter++;
-                                $line = ${$scriptref}[$valuecounter];
-                                installer::remover::remove_leading_and_ending_whitespaces(\$line);
-                                $itemvalue = $itemvalue . $line;
-                            }
-
-                            # removing ending ";"
-                            $itemvalue =~ s/\;\s*$//;
-                            
-                            $oneitemhash{$itemkey} = $itemvalue;
-    
-                            if ( $itemkey =~ /^\s*\S+\s+\(\S+\)\s*$/ )
-                            {
-                                $ismultilang = 1;			
-                            }
-                        }
+                    if ( $i >= $#{$scriptref} ) {
+                        installer::exiter::exit_program("Invalid setup script file. Premature end of file.", "get_all_items_from_script");
                     }
-                }
+                    $line = ${$scriptref}[++$i];
+                    installer::remover::remove_leading_and_ending_whitespaces(\$line);
+                    $itemvalue .= $line;
+                } while (!($line =~ /\)\;\s*$/));
+
+                # removing ending ";"
+                $itemvalue =~ s/\;\s*$//;
+
+                $oneitemhash{$itemkey} = $itemvalue;
+
+                $ismultilang ||= $itemkey =~ /^\S+\s+\(\S+\)$/;
             }
-            
-            $oneitemhash{'ismultilingual'} = $ismultilang;
-            
-            push(@allitemarray, \%oneitemhash);
         }
+
+        $oneitemhash{'ismultilingual'} = $ismultilang+0;
+
+        push(@allitemarray, \%oneitemhash);
     }
-        
+
     return \@allitemarray;
 }
 
-- 
1.7.1


--J2SCkAp4GZ/dPZZf--


More information about the LibreOffice mailing list