Skip to content
Snippets Groups Projects
Commit 896d4e82 authored by Andy Yates's avatar Andy Yates
Browse files

Faster version of rearrange which ditches uc() and order modifying in favor of...

Faster version of rearrange which ditches uc() and order modifying in favor of editing the input parameters directly with a tr///d. This is 35% faster than our original implementation. Test case suite has been run before this commit.
parent 3466e5da
No related branches found
No related tags found
No related merge requests found
......@@ -140,19 +140,20 @@ sub rearrange {
unless ( @_ && $_[0] && substr( $_[0], 0, 1 ) eq '-' ) {
return @_;
}
# Convert all of the parameter names to uppercase, and create a
# hash with parameter names as keys, and parameter values as values
my $i = 0;
my (%param) = map {
if ($i) { $i--; $_; }
else { $i++; uc($_); }
} @_;
# Push undef onto the end if % 2 != 0 to stop warnings
push @_,undef unless $#_ %2;
my %param;
while( @_ ) {
#deletes all dashes & uppercases at the same time
(my $key = shift) =~ tr/a-z\055/A-Z/d;
$param{$key} = shift;
}
# What we intend to do is loop through the @{$order} variable,
# and for each value, we use that as a key into our associative
# array, pushing the value at that key onto our return array.
return map { $param{ uc("-$_") } } @$order;
return map { $param{uc($_)} } @$order;
}
1;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment