[Moose-commits] r7809 - Mouse/trunk/lib/Mouse/Meta
tokuhirom at code2.0beta.co.uk
tokuhirom at code2.0beta.co.uk
Mon Mar 2 01:36:44 GMT 2009
Author: tokuhirom
Date: 2009-03-01 17:36:44 -0800 (Sun, 01 Mar 2009)
New Revision: 7809
Modified:
Mouse/trunk/lib/Mouse/Meta/Class.pm
Log:
micro optimization for method modifiers.
do not eval everytime!
benchmark result is here:
Rate orig fastest
orig 4950/s -- -92%
fastest 62500/s 1162% --
Modified: Mouse/trunk/lib/Mouse/Meta/Class.pm
===================================================================
--- Mouse/trunk/lib/Mouse/Meta/Class.pm 2009-03-01 14:41:54 UTC (rev 7808)
+++ Mouse/trunk/lib/Mouse/Meta/Class.pm 2009-03-02 01:36:44 UTC (rev 7809)
@@ -187,25 +187,36 @@
sub _install_modifier {
my ( $self, $into, $type, $name, $code ) = @_;
- if (eval "require Class::Method::Modifiers::Fast; 1") {
- Class::Method::Modifiers::Fast::_install_modifier(
- $into,
- $type,
- $name,
- $code
- );
+
+ # which is modifer class available?
+ my $modifier_class = do {
+ if (eval "require Class::Method::Modifiers::Fast; 1") {
+ 'Class::Method::Modifiers::Fast';
+ } elsif (eval "require Class::Method::Modifiers; 1") {
+ 'Class::Method::Modifiers';
+ } else {
+ Carp::croak("Method modifiers require the use of Class::Method::Modifiers or Class::Method::Modifiers::Fast. Please install it from CPAN and file a bug report with this application.");
+ }
+ };
+ my $modifier = $modifier_class->can('_install_modifier');
+
+ # replace this method itself :)
+ {
+ no strict 'refs';
+ no warnings 'redefine';
+ *{__PACKAGE__ . '::_install_modifier'} = sub {
+ my ( $self, $into, $type, $name, $code ) = @_;
+ $modifier->(
+ $into,
+ $type,
+ $name,
+ $code
+ );
+ };
}
- elsif (eval "require Class::Method::Modifiers; 1") {
- Class::Method::Modifiers::_install_modifier(
- $into,
- $type,
- $name,
- $code
- );
- }
- else {
- Carp::croak("Method modifiers require the use of Class::Method::Modifiers. Please install it from CPAN and file a bug report with this application.");
- }
+
+ # call me. for first time.
+ $self->_install_modifier( $into, $type, $name, $code );
}
sub add_before_method_modifier {
More information about the Moose-commits
mailing list