From: Peter Rabbitson Date: Mon, 29 Nov 2010 06:22:51 +0000 (+0100) Subject: Indulge in some microoptimization X-Git-Tag: v0.08125~32 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cca282b601b57a8de658986fc3f0d789a72749ea;p=dbsrgits%2FDBIx-Class.git Indulge in some microoptimization Per: http://lists.scsys.co.uk/pipermail/dbix-class/2010-November/009600.html and http://lists.scsys.co.uk/pipermail/dbix-class/2010-November/009601.html --- diff --git a/lib/DBIx/Class/Ordered.pm b/lib/DBIx/Class/Ordered.pm index 049d9c6..b6c4177 100644 --- a/lib/DBIx/Class/Ordered.pm +++ b/lib/DBIx/Class/Ordered.pm @@ -628,11 +628,10 @@ sub update { } my @res; - my $want = wantarray(); - if (not defined $want) { + if (not defined wantarray) { $self->next::method( \%upd, @_ ); } - elsif ($want) { + elsif (wantarray) { @res = $self->next::method( \%upd, @_ ); } else { @@ -640,7 +639,7 @@ sub update { } $guard->commit; - return $want ? @res : $res[0]; + return wantarray ? @res : $res[0]; } } @@ -660,11 +659,10 @@ sub delete { $self->move_last; my @res; - my $want = wantarray(); - if (not defined $want) { + if (not defined wantarray) { $self->next::method( @_ ); } - elsif ($want) { + elsif (wantarray) { @res = $self->next::method( @_ ); } else { @@ -672,7 +670,7 @@ sub delete { } $guard->commit; - return $want ? @res : $res[0]; + return wantarray ? @res : $res[0]; } =head1 METHODS FOR EXTENDING ORDERED diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index db6c27e..02cee66 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -271,11 +271,10 @@ sub search { my $self = shift; my $rs = $self->search_rs( @_ ); - my $want = wantarray; - if ($want) { + if (wantarray) { return $rs->all; } - elsif (defined $want) { + elsif (defined wantarray) { return $rs; } else { diff --git a/lib/DBIx/Class/Storage.pm b/lib/DBIx/Class/Storage.pm index 6134b39..89c5ef8 100644 --- a/lib/DBIx/Class/Storage.pm +++ b/lib/DBIx/Class/Storage.pm @@ -229,7 +229,7 @@ sub txn_do { $self->throw_exception($error); # txn failed but rollback succeeded }; - return $wantarray ? @return_values : $return_value; + return wantarray ? @return_values : $return_value; } =head2 txn_begin diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 6b6f7dd..3bd9fab 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -772,7 +772,7 @@ sub txn_do { local $self->{_in_dbh_do} = 1; my @result; - my $want_array = wantarray; + my $want = wantarray; my $tried = 0; while(1) { @@ -784,10 +784,10 @@ sub txn_do { try { $self->txn_begin; my $txn_start_depth = $self->transaction_depth; - if($want_array) { + if($want) { @result = $coderef->(@$args); } - elsif(defined $want_array) { + elsif(defined $want) { $result[0] = $coderef->(@$args); } else { @@ -806,7 +806,7 @@ sub txn_do { $exception = $_; }; - if(! defined $exception) { return $want_array ? @result : $result[0] } + if(! defined $exception) { return wantarray ? @result : $result[0] } if($self->transaction_depth > 1 || $tried++ || $self->connected) { my $rollback_exception; @@ -2641,8 +2641,7 @@ sub deployment_statements { ); my @ret; - my $wa = wantarray; - if ($wa) { + if (wantarray) { @ret = $tr->translate; } else { @@ -2652,7 +2651,7 @@ sub deployment_statements { $self->throw_exception( 'Unable to produce deployment statements: ' . $tr->error) unless (@ret && defined $ret[0]); - return $wa ? @ret : $ret[0]; + return wantarray ? @ret : $ret[0]; } sub deploy { diff --git a/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm b/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm index b255e53..be1faf8 100644 --- a/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm +++ b/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm @@ -257,16 +257,16 @@ sub _dbh_execute { my ($dbh, $op, $extra_bind, $ident, $bind_attributes, @args) = @_; my (@res, $tried); - my $wantarray = wantarray(); + my $want = wantarray; my $next = $self->next::can; do { try { my $exec = sub { $self->$next($dbh, $op, $extra_bind, $ident, $bind_attributes, @args) }; - if (!defined $wantarray) { + if (!defined $want) { $exec->(); } - elsif (! $wantarray) { + elsif (! $want) { $res[0] = $exec->(); } else { @@ -288,7 +288,7 @@ sub _dbh_execute { }; } while (! $tried++); - return $wantarray ? @res : $res[0]; + return wantarray ? @res : $res[0]; } =head2 get_autoinc_seq diff --git a/lib/DBIx/Class/Storage/DBI/Replicated.pm b/lib/DBIx/Class/Storage/DBI/Replicated.pm index 54ca793..01de0de 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated.pm @@ -408,8 +408,6 @@ C, C, C and C. around connect_info => sub { my ($next, $self, $info, @extra) = @_; - my $wantarray = wantarray; - my $merge = Hash::Merge->new('LEFT_PRECEDENT'); my %opts; @@ -446,11 +444,11 @@ around connect_info => sub { $self->_master_connect_info_opts(\%opts); - my (@res, $res); - if ($wantarray) { + my @res; + if (wantarray) { @res = $self->$next($info, @extra); } else { - $res = $self->$next($info, @extra); + $res[0] = $self->$next($info, @extra); } # Make sure master is blessed into the correct class and apply role to it. @@ -463,7 +461,7 @@ around connect_info => sub { # link pool back to master $self->pool->master($master); - $wantarray ? @res : $res; + wantarray ? @res : $res[0]; }; =head1 METHODS @@ -678,7 +676,7 @@ sub execute_reliably { $self->read_handler($current); }; - return $want_array ? @result : $result[0]; + return wantarray ? @result : $result[0]; } =head2 set_reliable_storage diff --git a/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm b/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm index 14f34cd..c90af2f 100644 --- a/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm +++ b/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm @@ -436,8 +436,6 @@ sub update { my $self = shift; my ($source, $fields, $where, @rest) = @_; - my $wantarray = wantarray; - my $blob_cols = $self->_remove_blob_cols($source, $fields); my $table = $source->name; @@ -475,10 +473,10 @@ sub update { my @res; if (%$fields) { - if ($wantarray) { + if (wantarray) { @res = $self->next::method(@_); } - elsif (defined $wantarray) { + elsif (defined wantarray) { $res[0] = $self->next::method(@_); } else { @@ -488,7 +486,7 @@ sub update { $guard->commit; - return $wantarray ? @res : $res[0]; + return wantarray ? @res : $res[0]; } sub insert_bulk {