Skip to content

Commit

Permalink
improved Mojo::Collection performance
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jul 24, 2014
1 parent cdee141 commit a9a574a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -2,6 +2,7 @@
5.17 2014-07-24
- Welcome to the Mojolicious core team Jan Henning Thorsen.
- Added val method to Mojo::DOM. (batman, sri)
- Improved Mojo::Collection performance.

5.16 2014-07-21
- Improved Mojo::Asset::File to allow appending data to existing files.
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/Collection.pm
Expand Up @@ -26,7 +26,7 @@ sub DESTROY { }
sub c { __PACKAGE__->new(@_) }

sub compact {
shift->grep(sub { length($_ // '') });
$_[0]->new(grep { defined $_ && (ref $_ || length $_) } @{$_[0]});
}

sub each {
Expand Down Expand Up @@ -70,7 +70,7 @@ sub new {

sub pluck {
my ($self, $method, @args) = @_;
return $self->map(sub { $_->$method(@args) });
return $self->new(map { $_->$method(@args) } @$self);
}

sub reverse { $_[0]->new(reverse @{$_[0]}) }
Expand All @@ -93,7 +93,7 @@ sub tap { shift->Mojo::Base::tap(@_) }

sub uniq {
my %seen;
return shift->grep(sub { !$seen{$_}++ });
return $_[0]->new(grep { !$seen{$_}++ } @{$_[0]});
}

sub _flatten {
Expand Down
8 changes: 4 additions & 4 deletions lib/Mojo/DOM.pm
Expand Up @@ -547,10 +547,10 @@ from L<Mojo::DOM::CSS/"SELECTORS"> are supported.
=head2 attr
my $attrs = $dom->attr;
my $foo = $dom->attr('foo');
$dom = $dom->attr({foo => 'bar'});
$dom = $dom->attr(foo => 'bar');
my $hash = $dom->attr;
my $foo = $dom->attr('foo');
$dom = $dom->attr({foo => 'bar'});
$dom = $dom->attr(foo => 'bar');
This element's attributes.
Expand Down

0 comments on commit a9a574a

Please sign in to comment.