[Jifty-commit] r4660 - in jifty/trunk: lib/Jifty
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Mon Dec 10 00:46:56 EST 2007
Author: jesse
Date: Mon Dec 10 00:46:55 2007
New Revision: 4660
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Dispatcher.pm
Log:
r72845 at pinglin: jesse | 2007-12-10 00:46:07 -0500
* There's no need to compile Dispatcher rules to regexes every time they're evaluated. Cache them.
Modified: jifty/trunk/lib/Jifty/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Dispatcher.pm (original)
+++ jifty/trunk/lib/Jifty/Dispatcher.pm Mon Dec 10 00:46:55 2007
@@ -976,52 +976,60 @@
=cut
+
+my %CONDITION_CACHE;
+
sub _compile_condition {
my ( $self, $cond ) = @_;
# Previously compiled (eg. a qr{} -- return it verbatim)
return $cond if ref $cond;
- # Escape and normalize
- $cond = quotemeta($cond);
- $cond =~ s{(?:\\\/)+}{/}g;
- $cond =~ s{/$}{};
-
- my $has_capture = ( $cond =~ / \\ [*?#] /x);
- if ($has_capture or $cond =~ / \\ [[{] /x) {
- $cond = $self->_compile_glob($cond);
- }
+ unless ( $CONDITION_CACHE{$cond} ) {
- if ( $cond =~ m{^/} ) {
+ my $compiled = $cond;
- # '/foo' => qr{^/foo}
- $cond = "\\A$cond";
- } elsif ( length($cond) ) {
-
- # 'foo' => qr{^$cwd/foo}
- $cond = "(?<=\\A$self->{cwd}/)$cond";
- } else {
+ # Escape and normalize
+ $compiled = quotemeta($compiled);
+ $compiled =~ s{(?:\\\/)+}{/}g;
+ $compiled =~ s{/$}{};
+
+ my $has_capture = ( $compiled =~ / \\ [*?#] /x );
+ if ( $has_capture or $compiled =~ / \\ [[{] /x ) {
+ $compiled = $self->_compile_glob($compiled);
+ }
- # empty path -- just match $cwd itself
- $cond = "(?<=\\A$self->{cwd})";
- }
+ if ( $compiled =~ m{^/} ) {
+
+ # '/foo' => qr{^/foo}
+ $compiled = "\\A$compiled";
+ } elsif ( length($compiled) ) {
+
+ # 'foo' => qr{^$cwd/foo}
+ $compiled = "(?<=\\A$self->{cwd}/)$compiled";
+ } else {
- if ( $Dispatcher->{rule} eq 'on' ) {
+ # empty path -- just match $cwd itself
+ $compiled = "(?<=\\A$self->{cwd})";
+ }
- # "on" anchors on complete match only
- $cond .= '/?\\z';
- } else {
+ if ( $Dispatcher->{rule} eq 'on' ) {
- # "in" anchors on prefix match in directory boundary
- $cond .= '(?=/|\\z)';
- }
+ # "on" anchors on complete match only
+ $compiled .= '/?\\z';
+ } else {
- # Make all metachars into capturing submatches
- if (!$has_capture) {
- $cond = "($cond)";
- }
+ # "in" anchors on prefix match in directory boundary
+ $compiled .= '(?=/|\\z)';
+ }
- return qr{$cond};
+ # Make all metachars into capturing submatches
+ if ( !$has_capture ) {
+ $compiled = "($compiled)";
+ }
+ $CONDITION_CACHE{$cond} = qr{$compiled};
+ }
+ return $CONDITION_CACHE{$cond};
}
=head2 _compile_glob METAEXPRESSION
More information about the Jifty-commit
mailing list