Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 5, 2014
1 parent 1d98e3e commit 7039828
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,8 +1,9 @@

5.25 2014-08-05
- Added reduce method to Mojo::Collection.
- Fixed escaping bugs in Mojo::DOM::CSS.
- Improved sort method in Mojo::Collection to use $a and $b. (batman)
- Improved documentation browser CSS.
- Fixed escaping bugs in Mojo::DOM::CSS.

5.24 2014-08-02
- Improved url_escape performance slightly.
Expand Down
11 changes: 5 additions & 6 deletions lib/Mojo/Collection.pm
Expand Up @@ -97,12 +97,11 @@ sub sort {

my $caller = caller;
no strict 'refs';
return $self->new(
sort {
local (*{"$caller\::a"}, *{"$caller\::b"}) = (\$a, \$b);
$a->$cb($b);
} @$self
);
my @sorted = sort {
local (*{"$caller\::a"}, *{"$caller\::b"}) = (\$a, \$b);
$a->$cb($b);
} @$self;
return $self->new(@sorted);
}

sub tap { shift->Mojo::Base::tap(@_) }
Expand Down
3 changes: 1 addition & 2 deletions t/mojo/collection.t
Expand Up @@ -130,8 +130,7 @@ is_deeply [$collection->sort(sub { uc(shift) cmp uc(shift) })->each],
[qw(Mojo perl Test)], 'right order';
$collection = c();
is_deeply [$collection->sort->each], [], 'no elements';
is_deeply [$collection->sort(sub { $_[1] cmp $_[0] })->each], [],
'no elements';
is_deeply [$collection->sort(sub { $a cmp $b })->each], [], 'no elements';

# slice
$collection = c(1, 2, 3, 4, 5, 6, 7, 10, 9, 8);
Expand Down

0 comments on commit 7039828

Please sign in to comment.