From: Shawn M Moore Date: Wed, 3 Dec 2008 02:56:45 +0000 (+0000) Subject: Avoid calling $self->metaclass->meta again and again X-Git-Tag: 0.71_01~27 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=41885bab1fc5fa68466ee150943728522355451f;p=gitmo%2FClass-MOP.git Avoid calling $self->metaclass->meta again and again --- diff --git a/Changes b/Changes index efd899f..4897d07 100644 --- a/Changes +++ b/Changes @@ -4,6 +4,9 @@ Revision history for Perl extension Class-MOP. * Class::MOP::Method - Add an "execute" method to invoke the body so we can avoid using the coderef overload (Sartak) + * Class::MOP::Immutable + - Small speedup from eliminating several method + calls (Sartak) 0.71 Wed November 26, 2008 * Class::MOP::Class diff --git a/lib/Class/MOP/Immutable.pm b/lib/Class/MOP/Immutable.pm index 357cd75..58e10c1 100644 --- a/lib/Class/MOP/Immutable.pm +++ b/lib/Class/MOP/Immutable.pm @@ -243,12 +243,14 @@ sub create_methods_for_immutable_metaclass { my $self = shift; my %methods = %DEFAULT_METHODS; + my $metaclass = $self->metaclass; + my $meta = $metaclass->meta; foreach my $read_only_method (@{$self->options->{read_only}}) { - my $method = $self->metaclass->meta->find_method_by_name($read_only_method); + my $method = $meta->find_method_by_name($read_only_method); (defined $method) - || confess "Could not find the method '$read_only_method' in " . $self->metaclass->name; + || confess "Could not find the method '$read_only_method' in " . $metaclass->name; $methods{$read_only_method} = sub { confess "This method is read-only" if scalar @_ > 1; @@ -279,10 +281,10 @@ sub create_methods_for_immutable_metaclass { my $wrapped_methods = $self->options->{wrapped}; foreach my $method_name (keys %{ $wrapped_methods }) { - my $method = $self->metaclass->meta->find_method_by_name($method_name); + my $method = $meta->find_method_by_name($method_name); (defined $method) - || confess "Could not find the method '$method_name' in " . $self->metaclass->name; + || confess "Could not find the method '$method_name' in " . $metaclass->name; my $wrapper = $wrapped_methods->{$method_name};