Hi! Here are a few patches related to installer::sorter. I've tried to keep them low-risk, because much of the code is called during Windows builds, which I'm not yet testing.
I think the sort algorithm used currently in installer::sorter must be equivalent to bubble sort; in any case, I removed two of the subroutines, and replaced the third with a Schwartzian Transform (which might be overkill for this case, but I need to check the callers). I added a unit test for the remaining sort function, but I haven't tried to plug it in to the build system or anything. I tried to adapt the standard license header template to Perl comments. Kind regards, -- Tim Retout <t...@retout.co.uk>
From ba069516f1e512552a00a45cb7900822fab95ae3 Mon Sep 17 00:00:00 2001 From: Tim Retout <t...@retout.co.uk> Date: Wed, 15 Feb 2012 18:02:44 +0000 Subject: [PATCH 1/6] Turn on strictures in installer::sorter --- solenv/bin/modules/installer/sorter.pm | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/solenv/bin/modules/installer/sorter.pm b/solenv/bin/modules/installer/sorter.pm index dd983c06..4f3b9eb 100644 --- a/solenv/bin/modules/installer/sorter.pm +++ b/solenv/bin/modules/installer/sorter.pm @@ -27,6 +27,9 @@ package installer::sorter; +use strict; +use warnings; + ######################################### # Sorting an array of hashes ######################################### -- 1.7.8.3
From 2328049c111c5979e7ed10aa9fce8740f17ebd88 Mon Sep 17 00:00:00 2001 From: Tim Retout <t...@retout.co.uk> Date: Wed, 15 Feb 2012 19:17:04 +0000 Subject: [PATCH 2/6] Remove unnecessary sorting subroutines. --- solenv/bin/modules/installer/sorter.pm | 26 -------------------------- solenv/bin/modules/installer/worker.pm | 20 +------------------- 2 files changed, 1 insertions(+), 45 deletions(-) diff --git a/solenv/bin/modules/installer/sorter.pm b/solenv/bin/modules/installer/sorter.pm index 4f3b9eb..b61bb5b 100644 --- a/solenv/bin/modules/installer/sorter.pm +++ b/solenv/bin/modules/installer/sorter.pm @@ -90,30 +90,4 @@ sub sort_array_of_hashes_numerically } } -######################################### -# Sorting an array of of strings -######################################### - -sub sorting_array_of_strings -{ - my ($arrayref) = @_; - - for ( my $i = 0; $i <= $#{$arrayref}; $i++ ) - { - my $onestringunder = ${$arrayref}[$i]; - - for ( my $j = $i + 1; $j <= $#{$arrayref}; $j++ ) - { - my $onestringover = ${$arrayref}[$j]; - - if ( $onestringunder gt $onestringover) - { - ${$arrayref}[$i] = $onestringover; - ${$arrayref}[$j] = $onestringunder; - $onestringunder = $onestringover; - } - } - } -} - 1; diff --git a/solenv/bin/modules/installer/worker.pm b/solenv/bin/modules/installer/worker.pm index c91ece7..445f1dc 100644 --- a/solenv/bin/modules/installer/worker.pm +++ b/solenv/bin/modules/installer/worker.pm @@ -42,7 +42,6 @@ use installer::logger; use installer::pathanalyzer; use installer::scpzipfiles; use installer::scriptitems; -use installer::sorter; use installer::systemactions; use installer::windows::language; @@ -1533,23 +1532,6 @@ sub shift_file_to_end } ########################################################### -# Putting hash content into array and sorting it -########################################################### - -sub sort_hash -{ - my ( $hashref ) = @_; - - my $item = ""; - my @sortedarray = (); - - foreach $item (keys %{$hashref}) { push(@sortedarray, $item); } - installer::sorter::sorting_array_of_strings(\@sortedarray); - - return \@sortedarray; -} - -########################################################### # Renaming Windows files in Patch and creating file # patchfiles.txt ########################################################### @@ -1611,7 +1593,7 @@ sub prepare_windows_patchfiles my $patchlistfile = installer::existence::get_specified_file_by_name($filesref, $patchfilename); # reorganizing the patchfile content, sorting for directory to decrease the file size - my $sorteddirectorylist = sort_hash(\%patchfiledirectories); + my $sorteddirectorylist = [ sort keys %patchfiledirectories ]; my $patchfilelist = reorg_patchfile(\@patchfiles, $sorteddirectorylist); # shifting version.ini to the end of the list, to guarantee, that all files are patched -- 1.7.8.3
From 11df243b53f42348a1b6b697719ceef9c21688e1 Mon Sep 17 00:00:00 2001 From: Tim Retout <t...@retout.co.uk> Date: Wed, 15 Feb 2012 19:55:46 +0000 Subject: [PATCH 3/6] Inline and simplify installer::sorter::sort_array_of_hashes_numerically. --- solenv/bin/modules/installer/sorter.pm | 30 ----------------------- solenv/bin/modules/installer/windows/feature.pm | 13 ++++------ 2 files changed, 5 insertions(+), 38 deletions(-) diff --git a/solenv/bin/modules/installer/sorter.pm b/solenv/bin/modules/installer/sorter.pm index b61bb5b..91ed9ae 100644 --- a/solenv/bin/modules/installer/sorter.pm +++ b/solenv/bin/modules/installer/sorter.pm @@ -60,34 +60,4 @@ sub sorting_array_of_hashes } } -###################################################### -# Sorting an array of hashes with a numerical value -###################################################### - -sub sort_array_of_hashes_numerically -{ - my ($arrayref, $sortkey) = @_; - - for ( my $i = 0; $i <= $#{$arrayref}; $i++ ) - { - my $onehashunder = ${$arrayref}[$i]; - my $sortvalueunder = $onehashunder->{$sortkey}; - - for ( my $j = $i + 1; $j <= $#{$arrayref}; $j++ ) - { - my $onehashover = ${$arrayref}[$j]; - my $sortvalueover = $onehashover->{$sortkey}; - - if ( $sortvalueunder > $sortvalueover) - { - ${$arrayref}[$i] = $onehashover; - ${$arrayref}[$j] = $onehashunder; - - $onehashunder = $onehashover; - $sortvalueunder = $sortvalueover; - } - } - } -} - 1; diff --git a/solenv/bin/modules/installer/windows/feature.pm b/solenv/bin/modules/installer/windows/feature.pm index d570ec0..92d8cfe 100644 --- a/solenv/bin/modules/installer/windows/feature.pm +++ b/solenv/bin/modules/installer/windows/feature.pm @@ -31,7 +31,6 @@ use installer::existence; use installer::exiter; use installer::files; use installer::globals; -use installer::sorter; use installer::worker; use installer::windows::idtglobal; use installer::windows::language; @@ -244,8 +243,7 @@ sub collect_modules_recursive { if ( $directparent->{$modulegid} eq $parentid ) { - my %childhash = ( "gid" => "$modulegid", "Sortkey" => "$directsortkey->{$modulegid}"); - push(@allchildren, \%childhash); + push @allchildren, [ $directsortkey->{$modulegid}, $modulegid ]; $childrenexist = 1; } } @@ -255,14 +253,13 @@ sub collect_modules_recursive if ( $childrenexist ) { # Sort children - installer::sorter::sort_array_of_hashes_numerically(\@allchildren, "Sortkey"); + @allchildren = map { $_->[1] } + sort { $a->[0] <=> $b->[0] } + @allchildren; # Adding children to new array - my $childhashref; - foreach $childhashref ( @allchildren ) + foreach my $gid ( @allchildren ) { - my $gid = $childhashref->{'gid'}; - # Saving all lines, that have this 'gid' my $unique; -- 1.7.8.3
From eebe6852842001e1fc7de49efc218f46ddf711d2 Mon Sep 17 00:00:00 2001 From: Tim Retout <t...@retout.co.uk> Date: Wed, 15 Feb 2012 18:50:06 +0000 Subject: [PATCH 4/6] Use Exporter for installer::sorter --- solenv/bin/make_installer.pl | 8 ++++---- solenv/bin/modules/installer/sorter.pm | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/solenv/bin/make_installer.pl b/solenv/bin/make_installer.pl index 4f35aed..45dede0 100644 --- a/solenv/bin/make_installer.pl +++ b/solenv/bin/make_installer.pl @@ -57,7 +57,7 @@ use installer::scpzipfiles; use installer::scriptitems; use installer::setupscript; use installer::simplepackage; -use installer::sorter; +use installer::sorter qw(sorting_array_of_hashes); use installer::strip; use installer::substfilenamefiles; use installer::systemactions; @@ -1101,7 +1101,7 @@ for ( my $n = 0; $n <= $#installer::globals::languageproducts; $n++ ) if ( $installer::globals::globallogging ) { installer::files::save_array_of_hashes($loggingdir . "directoriesforepmlist3alangpack.log", $directoriesforepmarrayref); } ($directoriesforepmarrayref, $alldirectoryhash) = installer::scriptitems::collect_directories_with_create_flag_from_directoryarray($dirsinproductlanguageresolvedarrayref, $alldirectoryhash); if ( $installer::globals::globallogging ) { installer::files::save_array_of_hashes($loggingdir . "directoriesforepmlist3blangpack.log", $directoriesforepmarrayref); } - installer::sorter::sorting_array_of_hashes($directoriesforepmarrayref, "HostName"); + sorting_array_of_hashes($directoriesforepmarrayref, "HostName"); if ( $installer::globals::globallogging ) { installer::files::save_array_of_hashes($loggingdir . "directoriesforepmlist3clangpack.log", $directoriesforepmarrayref); } if ( $installer::globals::iswindowsbuild ) @@ -1130,7 +1130,7 @@ for ( my $n = 0; $n <= $#installer::globals::languageproducts; $n++ ) if ( $installer::globals::globallogging ) { installer::files::save_array_of_hashes($loggingdir . "directoriesforepmlist3ahelppack.log", $directoriesforepmarrayref); } ($directoriesforepmarrayref, $alldirectoryhash) = installer::scriptitems::collect_directories_with_create_flag_from_directoryarray($dirsinproductlanguageresolvedarrayref, $alldirectoryhash); if ( $installer::globals::globallogging ) { installer::files::save_array_of_hashes($loggingdir . "directoriesforepmlist3bhelppack.log", $directoriesforepmarrayref); } - installer::sorter::sorting_array_of_hashes($directoriesforepmarrayref, "HostName"); + sorting_array_of_hashes($directoriesforepmarrayref, "HostName"); if ( $installer::globals::globallogging ) { installer::files::save_array_of_hashes($loggingdir . "directoriesforepmlist3chelppack.log", $directoriesforepmarrayref); } if ( $installer::globals::iswindowsbuild ) @@ -1171,7 +1171,7 @@ for ( my $n = 0; $n <= $#installer::globals::languageproducts; $n++ ) ($directoriesforepmarrayref, $alldirectoryhash) = installer::scriptitems::collect_directories_from_filesarray($filesinproductlanguageresolvedarrayref); if ( $installer::globals::globallogging ) { installer::files::save_array_of_hashes($loggingdir . "directoriesforepmlist4_patch.log", $directoriesforepmarrayref); } - installer::sorter::sorting_array_of_hashes($directoriesforepmarrayref, "HostName"); + sorting_array_of_hashes($directoriesforepmarrayref, "HostName"); if ( $installer::globals::globallogging ) { installer::files::save_array_of_hashes($loggingdir . "directoriesforepmlist5_patch.log", $directoriesforepmarrayref); } } } diff --git a/solenv/bin/modules/installer/sorter.pm b/solenv/bin/modules/installer/sorter.pm index 91ed9ae..54e5c34 100644 --- a/solenv/bin/modules/installer/sorter.pm +++ b/solenv/bin/modules/installer/sorter.pm @@ -30,6 +30,12 @@ package installer::sorter; use strict; use warnings; +use base 'Exporter'; + +our @EXPORT_OK = qw( + sorting_array_of_hashes +); + ######################################### # Sorting an array of hashes ######################################### -- 1.7.8.3
From ecc53b1af90aaeb8b255624478ef51907931ddd3 Mon Sep 17 00:00:00 2001 From: Tim Retout <t...@retout.co.uk> Date: Wed, 15 Feb 2012 19:00:10 +0000 Subject: [PATCH 5/6] Add tests for installer::sorter --- solenv/bin/modules/t/installer-sorter.t | 48 +++++++++++++++++++++++++++++++ 1 files changed, 48 insertions(+), 0 deletions(-) create mode 100644 solenv/bin/modules/t/installer-sorter.t diff --git a/solenv/bin/modules/t/installer-sorter.t b/solenv/bin/modules/t/installer-sorter.t new file mode 100644 index 0000000..fe67b4e --- /dev/null +++ b/solenv/bin/modules/t/installer-sorter.t @@ -0,0 +1,48 @@ +# Version: MPL 1.1 / GPLv3+ / LGPLv3+ +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License or as specified alternatively below. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# Major Contributor(s): +# [ Copyright (C) 2012 Tim Retout <t...@retout.co.uk> (initial developer) ] +# +# All Rights Reserved. +# +# For minor contributions see the git repository. +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 3 or later (the "GPLv3+"), or +# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), +# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable +# instead of those above. + +use strict; +use warnings; + +use lib '.'; + +use Test::More; +use List::Util 'shuffle'; + +BEGIN { + use_ok('installer::sorter', qw( + sorting_array_of_hashes + )); +} + +my @loh_str_sorted = map { { "key" => $_ } } ("a".."j"); + +my @loh_str_random = shuffle @loh_str_sorted; + +sorting_array_of_hashes(\@loh_str_random, "key"); + +is_deeply(\@loh_str_random, \@loh_str_sorted); + +done_testing(); -- 1.7.8.3
From 31eeac3752d1c6e421a945a7aebfca859a2667df Mon Sep 17 00:00:00 2001 From: Tim Retout <t...@retout.co.uk> Date: Wed, 15 Feb 2012 20:08:57 +0000 Subject: [PATCH 6/6] Simplify installer::sorter::sorting_array_of_hashes. --- solenv/bin/modules/installer/sorter.pm | 24 ++++-------------------- 1 files changed, 4 insertions(+), 20 deletions(-) diff --git a/solenv/bin/modules/installer/sorter.pm b/solenv/bin/modules/installer/sorter.pm index 54e5c34..b08dd80 100644 --- a/solenv/bin/modules/installer/sorter.pm +++ b/solenv/bin/modules/installer/sorter.pm @@ -44,26 +44,10 @@ sub sorting_array_of_hashes { my ($arrayref, $sortkey) = @_; - for ( my $i = 0; $i <= $#{$arrayref}; $i++ ) - { - my $onehashunder = ${$arrayref}[$i]; - my $sortvalueunder = $onehashunder->{$sortkey}; - - for ( my $j = $i + 1; $j <= $#{$arrayref}; $j++ ) - { - my $onehashover = ${$arrayref}[$j]; - my $sortvalueover = $onehashover->{$sortkey}; - - if ( $sortvalueunder gt $sortvalueover) - { - ${$arrayref}[$i] = $onehashover; - ${$arrayref}[$j] = $onehashunder; - - $onehashunder = $onehashover; - $sortvalueunder = $sortvalueover; - } - } - } + @$arrayref = map { $_->[1] } + sort { $a->[0] cmp $b->[0] } + map { [$_->{$sortkey}, $_] } + @$arrayref; } 1; -- 1.7.8.3
_______________________________________________ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice