Skip to content

Commit

Permalink
improve performance of Mojo::File significantly
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 9, 2017
1 parent 46b7cda commit aceea20
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/Mojo/Asset/File.pm
Expand Up @@ -4,7 +4,7 @@ use Mojo::Base 'Mojo::Asset';
use Carp 'croak';
use Errno 'EEXIST';
use Fcntl qw(O_APPEND O_CREAT O_EXCL O_RDONLY O_RDWR);
use File::Spec;
use File::Spec::Functions ();
use IO::File;
use Mojo::File;
use Mojo::Util 'md5_sum';
Expand Down Expand Up @@ -35,7 +35,7 @@ has handle => sub {

return $handle;
};
has tmpdir => sub { $ENV{MOJO_TMPDIR} || File::Spec->tmpdir };
has tmpdir => sub { $ENV{MOJO_TMPDIR} || File::Spec::Functions::tmpdir };

sub DESTROY {
my $self = shift;
Expand Down
22 changes: 11 additions & 11 deletions lib/Mojo/File.pm
Expand Up @@ -13,7 +13,7 @@ use File::Basename ();
use File::Copy ();
use File::Find ();
use File::Path ();
use File::Spec;
use File::Spec::Functions qw(abs2rel catfile file_name_is_absolute splitdir);
use File::Temp ();
use Mojo::Collection;
use Scalar::Util 'blessed';
Expand All @@ -29,7 +29,7 @@ sub child {

sub dirname { $_[0]->new(scalar File::Basename::dirname ${$_[0]}) }

sub is_abs { File::Spec->file_name_is_absolute(${shift()}) }
sub is_abs { file_name_is_absolute ${shift()} }

sub list {
my ($self, $options) = (shift, shift // {});
Expand All @@ -38,7 +38,7 @@ sub list {
opendir(my $dir, $$self) or croak qq{Can't open directory "$$self": $!};
my @files = grep { $_ ne '.' && $_ ne '..' } readdir $dir;
@files = grep { !/^\./ } @files unless $options->{hidden};
@files = map { File::Spec->catfile($$self, $_) } @files;
@files = map { catfile $$self, $_ } @files;
@files = grep { !-d } @files unless $options->{dir};

return Mojo::Collection->new(map { $self->new($_) } sort @files);
Expand Down Expand Up @@ -76,17 +76,17 @@ sub move_to {

sub new {
my $class = shift;
my $self = bless \my $dummy, ref $class || $class;

unless (@_) { $$self = getcwd }
my $value;
unless (@_) { $value = getcwd }

elsif (@_ > 1) { $$self = File::Spec->catfile(@_) }
elsif (@_ > 1) { $value = catfile @_ }

elsif (blessed $_[0] && $_[0]->isa('File::Temp::Dir')) { $$self = $_[0] }
elsif (blessed $_[0] && $_[0]->isa('File::Temp::Dir')) { $value = $_[0] }

else { $$self = shift }
else { $value = shift }

return $self;
return bless \$value, ref $class || $class;
}

sub path { __PACKAGE__->new(@_) }
Expand Down Expand Up @@ -116,9 +116,9 @@ sub tempdir { __PACKAGE__->new(File::Temp->newdir(@_)) }

sub to_abs { $_[0]->new(abs_path ${$_[0]}) }

sub to_array { [File::Spec->splitdir(${shift()})] }
sub to_array { [splitdir ${shift()}] }

sub to_rel { $_[0]->new(File::Spec->abs2rel(${$_[0]}, $_[1])) }
sub to_rel { $_[0]->new(abs2rel(${$_[0]}, $_[1])) }

sub to_string {"${$_[0]}"}

Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/Server/Prefork.pm
Expand Up @@ -2,7 +2,7 @@ package Mojo::Server::Prefork;
use Mojo::Base 'Mojo::Server::Daemon';

use Config;
use File::Spec;
use File::Spec::Functions 'tmpdir';
use Mojo::File 'path';
use Mojo::Util 'steady_time';
use POSIX 'WNOHANG';
Expand All @@ -12,8 +12,8 @@ has accepts => 10000;
has cleanup => 1;
has [qw(graceful_timeout heartbeat_timeout)] => 20;
has heartbeat_interval => 5;
has pid_file => sub { path(File::Spec->tmpdir, 'prefork.pid')->to_string };
has workers => 4;
has pid_file => sub { path(tmpdir, 'prefork.pid')->to_string };
has workers => 4;

sub DESTROY { unlink $_[0]->pid_file if $_[0]->cleanup }

Expand Down

0 comments on commit aceea20

Please sign in to comment.