[PATCH] Accelerate Perl installer builder
Jan Darmochwal
jdarmochwal at gmx.de
Fri Feb 25 02:23:25 PST 2011
* subs in converter.pl rewritten
* fixed bug in convert_whitespace_stringlist_into_array
* removed copy_array_from_reference (can be written as "$copy = [@{$source}]")
* removed copy_hash_from_reference (can be written as "$copy = {%{$source}}")
* removed convert_stringlist_into_array_without_linebreak_and_quotes
(equivalent to convert_stringlist_into_array_without_newline)
---
solenv/bin/modules/installer/archivefiles.pm | 2 +-
solenv/bin/modules/installer/converter.pm | 269 +++------------------
solenv/bin/modules/installer/helppack.pm | 4 +-
solenv/bin/modules/installer/languagepack.pm | 4 +-
solenv/bin/modules/installer/windows/idtglobal.pm | 4 +-
solenv/bin/modules/installer/worker.pm | 50 +----
solenv/bin/modules/installer/xpdinstaller.pm | 2 +-
7 files changed, 48 insertions(+), 287 deletions(-)
diff --git a/solenv/bin/modules/installer/archivefiles.pm b/solenv/bin/modules/installer/archivefiles.pm
index 3cd07b7..34fff6c 100644
--- a/solenv/bin/modules/installer/archivefiles.pm
+++ b/solenv/bin/modules/installer/archivefiles.pm
@@ -88,7 +88,7 @@ sub get_patch_file_list
$patchfilestring =~ s/^\s*\///;
$patchfilestring =~ s/^\s*\\//;
- my $patchfilesarray = installer::converter::convert_stringlist_into_array_without_linebreak_and_quotes(\$patchfilestring, ",");
+ my $patchfilesarray = installer::converter::convert_stringlist_into_array_without_newline(\$patchfilestring, ",");
return $patchfilesarray;
}
diff --git a/solenv/bin/modules/installer/converter.pm b/solenv/bin/modules/installer/converter.pm
index 24be74e..ea95fb8 100644
--- a/solenv/bin/modules/installer/converter.pm
+++ b/solenv/bin/modules/installer/converter.pm
@@ -35,20 +35,14 @@ use installer::globals;
sub convert_array_to_hash
{
- my ($arrayref) = @_;
-
+ my ($arrayref) = @_;
+
my %newhash = ();
- for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
+ for (@{$arrayref})
{
- my $line = ${$arrayref}[$i];
-
- if ( $line =~ /^\s*([\w-]+?)\s+(.*?)\s*$/ )
- {
- my $key = $1;
- my $value = $2;
- $newhash{$key} = $value;
- }
+ next unless /^\s*([\w-]+?)\s+(.*?)\s*$/;
+ $newhash{$1} = $2;
}
return \%newhash;
@@ -58,44 +52,7 @@ sub convert_hash_into_array
{
my ($hashref) = @_;
- my @array = ();
- my $key;
-
- foreach $key (keys %{$hashref})
- {
- my $value = $hashref->{$key};
- my $input = "$key = $value\n";
- push(@array ,$input);
- }
-
- return \@array
-}
-
-#############################################################################
-# Converting a string list with separator $listseparator
-# into an array
-#############################################################################
-
-sub convert_stringlist_into_array_without_linebreak_and_quotes
-{
- my ( $includestringref, $listseparator ) = @_;
-
- my @newarray = ();
- my $first;
- my $last = ${$includestringref};
-
- while ( $last =~ /^\s*(.+?)\Q$listseparator\E(.+)\s*$/) # "$" for minimal matching
- {
- $first = $1;
- $last = $2;
- $first =~ s/\"//g;
- push(@newarray, $first);
- }
-
- $last =~ s/\"//g;
- push(@newarray, $last);
-
- return \@newarray;
+ return [map { "$_ = $hashref->{$_}\n" } keys %{$hashref}];
}
#############################################################################
@@ -107,22 +64,7 @@ sub convert_stringlist_into_array
{
my ( $includestringref, $listseparator ) = @_;
- my @newarray = ();
- my $first;
- my $last = ${$includestringref};
-
- while ( $last =~ /^\s*(.+?)\Q$listseparator\E(.+)\s*$/) # "$" for minimal matching
- {
- $first = $1;
- $last = $2;
- # Problem with two directly following listseparators. For example a path with two ";;" directly behind each other
- $first =~ s/^$listseparator//;
- push(@newarray, "$first\n");
- }
-
- push(@newarray, "$last\n");
-
- return \@newarray;
+ return [map "$_\n", split /\Q$listseparator\E\s*/, ${$includestringref}];
}
#############################################################################
@@ -134,20 +76,7 @@ sub convert_stringlist_into_array_without_newline
{
my ( $includestringref, $listseparator ) = @_;
- my @newarray = ();
- my $first;
- my $last = ${$includestringref};
-
- while ( $last =~ /^\s*(.+?)\Q$listseparator\E(.+)\s*$/) # "$" for minimal matching
- {
- $first = $1;
- $last = $2;
- push(@newarray, "$first");
- }
-
- push(@newarray, "$last");
-
- return \@newarray;
+ return [split /\Q$listseparator\E\s*/, ${$includestringref}];
}
#############################################################################
@@ -159,20 +88,7 @@ sub convert_stringlist_into_hash
{
my ( $includestringref, $listseparator ) = @_;
- my %newhash = ();
- my $first;
- my $last = ${$includestringref};
-
- while ( $last =~ /^\s*(.+?)\Q$listseparator\E(.+)\s*$/) # "$" for minimal matching
- {
- $first = $1;
- $last = $2;
- $newhash{$first} = 1;
- }
-
- $newhash{$last} = 1;
-
- return \%newhash;
+ return {map {$_, 1} split /\Q$listseparator\E\s*/, ${$includestringref}};
}
#############################################################################
@@ -184,20 +100,11 @@ sub convert_whitespace_stringlist_into_array
{
my ( $includestringref ) = @_;
- my @newarray = ();
- my $first;
- my $last = ${$includestringref};
-
- while ( $last =~ /^\s*(\S+?)\s+(\S+)\s*$/) # "$" for minimal matching
- {
- $first = $1;
- $last = $2;
- push(@newarray, "$first\n");
- }
+ my $tmp = ${$includestringref};
+ $tmp = s/^\s+//;
+ $tmp = s/\s+$//;
- push(@newarray, "$last\n");
-
- return \@newarray;
+ return [map "$_\n", split /\s+/, $tmp];
}
#############################################################################
@@ -208,16 +115,13 @@ sub convert_array_to_comma_separated_string
{
my ( $arrayref ) = @_;
- my $newstring = "";
-
- for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
- {
- my $arrayentry = ${$arrayref}[$i];
- $arrayentry =~ s/\s*$//;
- $newstring = $newstring . $arrayentry . ",";
+ my $newstring;
+ for (@{$arrayref}) {
+ my $tmp = $_;
+ $tmp =~ s/\s+$//;
+ $newstring .= "$tmp,";
}
-
- $newstring =~ s/\,\s*$//;
+ $newstring =~ s/\,$//;
return $newstring;
}
@@ -230,16 +134,13 @@ sub convert_array_to_space_separated_string
{
my ( $arrayref ) = @_;
- my $newstring = "";
-
- for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
- {
- my $arrayentry = ${$arrayref}[$i];
- $arrayentry =~ s/\s*$//;
- $newstring = $newstring . $arrayentry . " ";
+ my $newstring;
+ for (@{$arrayref}) {
+ my $tmp = $_;
+ $tmp =~ s/\s+$//;
+ $newstring .= "$tmp ";
}
-
- $newstring =~ s/\s*$//;
+ $newstring =~ s/ $//;
return $newstring;
}
@@ -253,9 +154,8 @@ sub convert_slash_to_backslash
{
my ($filesarrayref) = @_;
- for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
+ for my $onefile (@{$filesarrayref})
{
- my $onefile = ${$filesarrayref}[$i];
if ( $onefile->{'Name'} ) { $onefile->{'Name'} =~ s/\//\\/g; }
}
}
@@ -268,12 +168,8 @@ sub convert_slash_to_backslash
sub copy_item_object
{
my ($olditemhashref, $newitemhashref) = @_;
-
- foreach $key (keys %{$olditemhashref})
- {
- my $value = $olditemhashref->{$key};
- $newitemhashref->{$key} = $value;
- }
+
+ $newitemhashref = {%{$olditemhashref}};
}
#################################################################
@@ -286,18 +182,9 @@ sub copy_item_object
sub make_path_conform
{
my ( $path ) = @_;
+ my $s = $installer::globals::separator;
- my $oldpath = $path;
-
- while ( $path =~ /(^.*)(\Q$installer::globals::separator\E.*?[^\.])(\Q$installer::globals::separator\E\.\.)(\Q$installer::globals::separator\E.*$)/ )
- {
- my $part1 = $1;
- my $part2 = $4;
-
- # $2 must not end with a "." ! Problem with "..\.."
-
- $path = $part1 . $part2;
- }
+ while ($path =~ s/[^\.\Q$s\E]+?\Q$s\E\.\.(?:\Q$s\E|$)//g) {}
return $path;
}
@@ -309,61 +196,7 @@ sub make_path_conform
sub copy_collector
{
- my ( $oldcollector ) = @_;
-
- my @newcollector = ();
-
- for ( my $i = 0; $i <= $#{$oldcollector}; $i++ )
- {
- my %newhash = ();
- my $key;
-
- foreach $key (keys %{${$oldcollector}[$i]})
- {
- $newhash{$key} = ${$oldcollector}[$i]->{$key};
- }
-
- push(@newcollector, \%newhash);
- }
-
- return \@newcollector;
-}
-
-#################################################################
-# Copying an array
-#################################################################
-
-sub copy_array_from_references
-{
- my ( $arrayref ) = @_;
-
- my @newarray = ();
-
- for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
- {
- push(@newarray, ${$arrayref}[$i]);
- }
-
- return \@newarray;
-}
-
-###########################################################
-# Copying a hash
-###########################################################
-
-sub copy_hash_from_references
-{
- my ($hashref) = @_;
-
- my %newhash = ();
- my $key;
-
- foreach $key (keys %{$hashref})
- {
- $newhash{$key} = $hashref->{$key};
- }
-
- return \%newhash;
+ return [map { {%{$_}} } @{$_[0]}];
}
#################################################################
@@ -376,41 +209,11 @@ sub combine_arrays_from_references_first_win
my $hashref1 = convert_array_to_hash($arrayref1);
my $hashref2 = convert_array_to_hash($arrayref2);
- my %commonhash = ();
- my @newarray = ();
- # starting with second hash
- foreach my $key ( keys %{$hashref2} ) { $commonhash{$key} = $hashref2->{$key}; }
- # overwriting with first hash
- foreach my $key ( keys %{$hashref1} ) { $commonhash{$key} = $hashref1->{$key}; }
-
- # Creating the new array
- foreach my $key ( keys %commonhash ) { push(@newarray, "$key $commonhash{$key}\n"); }
-
- return \@newarray;
-}
-
-#################################################################
-# Combining two arrays
-#################################################################
-
-sub combine_arrays_from_references
-{
- my ( $arrayref1, $arrayref2 ) = @_;
-
- my @newarray = ();
-
- for ( my $i = 0; $i <= $#{$arrayref1}; $i++ )
- {
- push(@newarray, ${$arrayref1}[$i]);
- }
-
- for ( my $i = 0; $i <= $#{$arrayref2}; $i++ )
- {
- push(@newarray, ${$arrayref2}[$i]);
- }
+ # add key-value pairs from hash1 to hash2 (overwrites existing keys)
+ @{$hashref2}{keys %{$hashref1}} = values %{$hashref1};
- return \@newarray;
+ return [map { "$_ $hashref2->{$_}\n" } keys %{$hashref2}];
}
#################################################################
@@ -453,9 +256,9 @@ sub resolve_masked_separator
{
my ($arrayref, $separator, $replacementstring) = @_;
- for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
+ for (@{$arrayref})
{
- ${$arrayref}[$i] =~ s/$replacementstring/$separator/g
+ s/$replacementstring/$separator/g;
}
}
diff --git a/solenv/bin/modules/installer/helppack.pm b/solenv/bin/modules/installer/helppack.pm
index 21d2f04..027571c 100644
--- a/solenv/bin/modules/installer/helppack.pm
+++ b/solenv/bin/modules/installer/helppack.pm
@@ -211,7 +211,7 @@ sub determine_packagename
my $fileextension = "rpm";
my $rpmfiles = installer::systemactions::find_file_with_file_extension($fileextension, $installdir);
if ( ! ( $#{$rpmfiles} > -1 )) { installer::exiter::exit_program("ERROR: Could not find package in directory $installdir!", "determine_packagename"); }
- my $rpmsav = installer::converter::copy_array_from_references($rpmfiles);
+ my $rpmsav = [@{$rpmfiles}];
for ( my $i = 0; $i <= $#{$rpmfiles}; $i++ ) { installer::pathanalyzer::make_absolute_filename_to_relative_filename(\${$rpmfiles}[$i]); }
$packagename = get_packagename_from_packagelist($rpmfiles, $allvariables, $languagestringref);
@@ -233,7 +233,7 @@ sub determine_packagename
my $alldirs = installer::systemactions::get_all_directories($installdir);
if ( ! ( $#{$alldirs} > -1 )) { installer::exiter::exit_program("ERROR: Could not find package in directory $installdir!", "determine_packagename"); }
- my $alldirssav = installer::converter::copy_array_from_references($alldirs);
+ my $alldirssav = [@{$alldirs}];
for ( my $i = 0; $i <= $#{$alldirs}; $i++ ) { installer::pathanalyzer::make_absolute_filename_to_relative_filename(\${$alldirs}[$i]); }
$packagename = get_packagename_from_packagelist($alldirs, $allvariables, $languagestringref);
diff --git a/solenv/bin/modules/installer/languagepack.pm b/solenv/bin/modules/installer/languagepack.pm
index 3c1c560..b7af3bb 100644
--- a/solenv/bin/modules/installer/languagepack.pm
+++ b/solenv/bin/modules/installer/languagepack.pm
@@ -198,7 +198,7 @@ sub determine_packagename
my $fileextension = "rpm";
my $rpmfiles = installer::systemactions::find_file_with_file_extension($fileextension, $installdir);
if ( ! ( $#{$rpmfiles} > -1 )) { installer::exiter::exit_program("ERROR: Could not find package in directory $installdir!", "determine_packagename"); }
- my $rpmsav = installer::converter::copy_array_from_references($rpmfiles);
+ my $rpmsav = [@{$rpmfiles}];
for ( my $i = 0; $i <= $#{$rpmfiles}; $i++ ) { installer::pathanalyzer::make_absolute_filename_to_relative_filename(\${$rpmfiles}[$i]); }
$packagename = get_packagename_from_packagelist($rpmfiles, $allvariables, $languagestringref);
@@ -220,7 +220,7 @@ sub determine_packagename
my $alldirs = installer::systemactions::get_all_directories($installdir);
if ( ! ( $#{$alldirs} > -1 )) { installer::exiter::exit_program("ERROR: Could not find package in directory $installdir!", "determine_packagename"); }
- my $alldirssav = installer::converter::copy_array_from_references($alldirs);
+ my $alldirssav = [@{$alldirs}];
for ( my $i = 0; $i <= $#{$alldirs}; $i++ ) { installer::pathanalyzer::make_absolute_filename_to_relative_filename(\${$alldirs}[$i]); }
$packagename = get_packagename_from_packagelist($alldirs, $allvariables, $languagestringref);
diff --git a/solenv/bin/modules/installer/windows/idtglobal.pm b/solenv/bin/modules/installer/windows/idtglobal.pm
index 1abeeb6..d181fd2 100644
--- a/solenv/bin/modules/installer/windows/idtglobal.pm
+++ b/solenv/bin/modules/installer/windows/idtglobal.pm
@@ -1269,7 +1269,7 @@ sub set_custom_action
# All files are located in $filesref and in @installer::globals::binarytableonlyfiles.
# Both must be added together
- my $localfilesref = installer::converter::combine_arrays_from_references(\@installer::globals::binarytableonlyfiles, $filesref);
+ my $localfilesref = [@installer::globals::binarytableonlyfiles, @{$filesref}];
for ( my $i = 0; $i <= $#{$localfilesref}; $i++ )
{
@@ -1347,7 +1347,7 @@ sub add_custom_action_to_install_table
# All files are located in $filesref and in @installer::globals::binarytableonlyfiles.
# Both must be added together
- my $localfilesref = installer::converter::combine_arrays_from_references(\@installer::globals::binarytableonlyfiles, $filesref);
+ my $localfilesref = [@installer::globals::binarytableonlyfiles, @{$filesref}];
for ( my $i = 0; $i <= $#{$localfilesref}; $i++ )
{
diff --git a/solenv/bin/modules/installer/worker.pm b/solenv/bin/modules/installer/worker.pm
index 7b420d5..9fd8831 100644
--- a/solenv/bin/modules/installer/worker.pm
+++ b/solenv/bin/modules/installer/worker.pm
@@ -546,43 +546,6 @@ sub clean_jds_temp_dirs
}
###########################################################
-# Copying a reference array
-###########################################################
-
-sub copy_array_from_references
-{
- my ( $arrayref ) = @_;
-
- my @newarray = ();
-
- for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
- {
- push(@newarray, ${$arrayref}[$i]);
- }
-
- return \@newarray;
-}
-
-###########################################################
-# Copying a reference hash
-###########################################################
-
-sub copy_hash_from_references
-{
- my ($hashref) = @_;
-
- my %newhash = ();
- my $key;
-
- foreach $key (keys %{$hashref})
- {
- $newhash{$key} = $hashref->{$key};
- }
-
- return \%newhash;
-}
-
-###########################################################
# Setting one language in the language independent
# array of include pathes with $(LANG)
###########################################################
@@ -1777,14 +1740,9 @@ sub get_all_files_from_filelist
my @allpackages = ();
- for ( my $i = 0; $i <= $#{$listfile}; $i++ )
- {
- my $line = ${$listfile}[$i];
- if ( $line =~ /^\s*\#/ ) { next; } # this is a comment line
- if ( $line =~ /^\s*$/ ) { next; } # empty line
- $line =~ s/^\s*//;
- $line =~ s/\s*$//;
- push(@allpackages, $line);
+ for (@{$listfile}) {
+ next unless /^\s*+([^#].*?)\s*$/;
+ push @allpackages, $1;
}
return \@allpackages;
@@ -2299,7 +2257,7 @@ sub add_variables_from_inc_to_hashref
my $includefilelist = "";
if ( $allvariables->{'ADD_INCLUDE_FILES'} ) { $includefilelist = $allvariables->{'ADD_INCLUDE_FILES'}; }
- my $includefiles = installer::converter::convert_stringlist_into_array_without_linebreak_and_quotes(\$includefilelist, ",");
+ my $includefiles = installer::converter::convert_stringlist_into_array_without_newline(\$includefilelist, ",");
for ( my $i = 0; $i <= $#{$includefiles}; $i++ )
{
diff --git a/solenv/bin/modules/installer/xpdinstaller.pm b/solenv/bin/modules/installer/xpdinstaller.pm
index fd08ed9..e65dec8 100644
--- a/solenv/bin/modules/installer/xpdinstaller.pm
+++ b/solenv/bin/modules/installer/xpdinstaller.pm
@@ -1691,7 +1691,7 @@ sub create_xpd_file_for_systemintegration
my $infoline = "Creating xpd file for package: $newpackagename\n";
push( @installer::globals::logfileinfo, $infoline);
- my $childmodule = installer::worker::copy_hash_from_references($module);
+ my $childmodule = {%{$module}};
$childmodule->{'ParentID'} = $module->{'gid'}; # the module gid is the new parent
$childmodule->{'InstallOrder'} = $installer::globals::defaultsystemintinstallorder;
my $number = $i + 1;
--
1.7.1
--J2SCkAp4GZ/dPZZf--
More information about the LibreOffice
mailing list