[Catalyst-commits] r13036 - in Catalyst-Runtime/5.80/trunk: . lib
szbalint at dev.catalyst.perl.org
szbalint at dev.catalyst.perl.org
Mon Mar 8 06:48:51 GMT 2010
Author: szbalint
Date: 2010-03-08 06:48:51 +0000 (Mon, 08 Mar 2010)
New Revision: 13036
Modified:
Catalyst-Runtime/5.80/trunk/Changes
Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
Log:
Optimizing component lookup for the simple, common case and falling back on regexps otherwise. Noting the optimization in Changes. Also, adding myself to contributors.
Modified: Catalyst-Runtime/5.80/trunk/Changes
===================================================================
--- Catalyst-Runtime/5.80/trunk/Changes 2010-03-08 01:23:10 UTC (rev 13035)
+++ Catalyst-Runtime/5.80/trunk/Changes 2010-03-08 06:48:51 UTC (rev 13036)
@@ -4,11 +4,13 @@
- Log an extra line in debug mode with the response status code,
the content type and content length if available.
- Refactoring:
+ Refactoring / optimizations:
- Display of the end of hit debug messages has been factored out into
log_headers, log_request and log_response methods which all call
$c->dump_these so that there is a unified point from which to hook
in parameter filtering (for example).
+ - $c->model/view/controller have become a lot faster for non-regexp names
+ by using direct hash lookup instead of looping.
Bug fixed:
- DispatchType::Index's uri_for_action only returns for actions registered
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm 2010-03-08 01:23:10 UTC (rev 13035)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm 2010-03-08 06:48:51 UTC (rev 13036)
@@ -640,7 +640,13 @@
sub controller {
my ( $c, $name, @args ) = @_;
+ my $appclass = ref($c) || $c;
if( $name ) {
+ unless ( ref($name) ) { # Direct component hash lookup to avoid costly regexps
+ my $comps = $c->components;
+ my $check = $appclass."::Controller::".$name;
+ return $c->_filter_component( $comps->{$check}, @args ) if exists $comps->{$check};
+ }
my @result = $c->_comp_search_prefixes( $name, qw/Controller C/ );
return map { $c->_filter_component( $_, @args ) } @result if ref $name;
return $c->_filter_component( $result[ 0 ], @args );
@@ -674,6 +680,11 @@
my ( $c, $name, @args ) = @_;
my $appclass = ref($c) || $c;
if( $name ) {
+ unless ( ref($name) ) { # Direct component hash lookup to avoid costly regexps
+ my $comps = $c->components;
+ my $check = $appclass."::Model::".$name;
+ return $c->_filter_component( $comps->{$check}, @args ) if exists $comps->{$check};
+ }
my @result = $c->_comp_search_prefixes( $name, qw/Model M/ );
return map { $c->_filter_component( $_, @args ) } @result if ref $name;
return $c->_filter_component( $result[ 0 ], @args );
@@ -728,6 +739,11 @@
my $appclass = ref($c) || $c;
if( $name ) {
+ unless ( ref($name) ) { # Direct component hash lookup to avoid costly regexps
+ my $comps = $c->components;
+ my $check = $appclass."::View::".$name;
+ return $c->_filter_component( $comps->{$check}, @args ) if exists $comps->{$check};
+ }
my @result = $c->_comp_search_prefixes( $name, qw/View V/ );
return map { $c->_filter_component( $_, @args ) } @result if ref $name;
return $c->_filter_component( $result[ 0 ], @args );
@@ -3122,6 +3138,8 @@
sky: Arthur Bergman
+szbalint: Balint Szilakszi <szbalint at cpan.org>
+
t0m: Tomas Doran <bobtfish at bobtfish.net>
Ulf Edvinsson
More information about the Catalyst-commits
mailing list