From: Stevan Little Date: Mon, 28 Aug 2006 18:20:56 +0000 (+0000) Subject: slight speed improvements X-Git-Tag: 0_35~13^2~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=91e0eb4ac2962e557cddb12683d6cf3ad339409f;p=gitmo%2FClass-MOP.git slight speed improvements --- diff --git a/lib/Class/MOP.pm b/lib/Class/MOP.pm index 5ed90a1..b7d634c 100644 --- a/lib/Class/MOP.pm +++ b/lib/Class/MOP.pm @@ -182,17 +182,12 @@ Class::MOP::Class->meta->add_attribute( 'get_method_map' => sub { my $self = shift; my $map = $self->{'%:methods'}; - foreach my $symbol ($self->list_all_package_symbols('CODE')) { my $code = $self->get_package_symbol('&' . $symbol); - - next if exists $map->{$symbol} && - $map->{$symbol}->body == $code; - + next if exists $map->{$symbol} && $map->{$symbol}->body == $code; $map->{$symbol} = $self->method_metaclass->wrap($code); } - - return $map; + return $map; } }, default => sub { {} } diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index b33acd6..61d11b6 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -265,16 +265,11 @@ sub instance_metaclass { $_[0]->{'$:instance_metaclass'} } sub get_method_map { my $self = shift; my $map = $self->{'%:methods'}; - foreach my $symbol ($self->list_all_package_symbols('CODE')) { - next if exists $map->{$symbol} && - $map->{$symbol}->body == $self->get_package_symbol('&' . $symbol); - - $map->{$symbol} = $self->method_metaclass->wrap( - $self->get_package_symbol('&' . $symbol) - ); + my $code = $self->get_package_symbol('&' . $symbol); + next if exists $map->{$symbol} && $map->{$symbol}->body == $code; + $map->{$symbol} = $self->method_metaclass->wrap($code); } - return $map; } diff --git a/lib/Class/MOP/Method.pm b/lib/Class/MOP/Method.pm index 4aefe2d..d34604a 100644 --- a/lib/Class/MOP/Method.pm +++ b/lib/Class/MOP/Method.pm @@ -38,23 +38,17 @@ sub body { (shift)->{body} } # informational sub package_name { - my $code = shift->{body}; -# (blessed($code)) -# || confess "Can only ask the package name of a blessed CODE"; + my $code = (shift)->{body}; svref_2object($code)->GV->STASH->NAME; } sub name { - my $code = shift->{body}; -# (blessed($code)) -# || confess "Can only ask the package name of a blessed CODE"; + my $code = (shift)->{body}; svref_2object($code)->GV->NAME; } sub fully_qualified_name { my $code = shift; -# (blessed($code)) -# || confess "Can only ask the package name of a blessed CODE"; $code->package_name . '::' . $code->name; } @@ -155,12 +149,6 @@ sub get_original_method { sub add_before_modifier { my $code = shift; my $modifier = shift; - #(exists $MODIFIERS{$code}) - # || confess "You must first wrap your method before adding a modifier"; - (blessed($code)) - || confess "Can only ask the package name of a blessed CODE"; - #('CODE' eq (reftype($code) || '')) - # || confess "You must supply a CODE reference for a modifier"; unshift @{$code->{modifier_table}->{before}} => $modifier; $_build_wrapped_method->($code->{modifier_table}); } @@ -168,12 +156,6 @@ sub add_before_modifier { sub add_after_modifier { my $code = shift; my $modifier = shift; - #(exists $MODIFIERS{$code}) - # || confess "You must first wrap your method before adding a modifier"; - (blessed($code)) - || confess "Can only ask the package name of a blessed CODE"; - #('CODE' eq (reftype($code) || '')) - # || confess "You must supply a CODE reference for a modifier"; push @{$code->{modifier_table}->{after}} => $modifier; $_build_wrapped_method->($code->{modifier_table}); } @@ -196,12 +178,6 @@ sub add_after_modifier { sub add_around_modifier { my $code = shift; my $modifier = shift; - #(exists $MODIFIERS{$code}) - # || confess "You must first wrap your method before adding a modifier"; - (blessed($code)) - || confess "Can only ask the package name of a blessed CODE"; - #('CODE' eq (reftype($code) || '')) - # || confess "You must supply a CODE reference for a modifier"; unshift @{$code->{modifier_table}->{around}->{methods}} => $modifier; $code->{modifier_table}->{around}->{cache} = $compile_around_method->( @{$code->{modifier_table}->{around}->{methods}}, diff --git a/lib/Class/MOP/Package.pm b/lib/Class/MOP/Package.pm index 9116050..86114d4 100644 --- a/lib/Class/MOP/Package.pm +++ b/lib/Class/MOP/Package.pm @@ -189,10 +189,13 @@ sub remove_package_symbol { sub list_all_package_symbols { my ($self, $type_filter) = @_; return keys %{$self->namespace} unless defined $type_filter; + # NOTE: # or we can filter based on # type (SCALAR|ARRAY|HASH|CODE) my $namespace = $self->namespace; - return grep { defined(*{$namespace->{$_}}{$type_filter}) } keys %{$namespace}; + return grep { + defined(*{$namespace->{$_}}{$type_filter}) + } keys %{$namespace}; } 1;