From: Dave Rolsky Date: Sat, 14 Aug 2010 16:54:30 +0000 (+0200) Subject: Big optimization for get_method_list X-Git-Tag: 1.05~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ea6dca1713c5f12a07e165b0e5d70b9455682414;p=gitmo%2FClass-MOP.git Big optimization for get_method_list By checking for a CODE slot in the glob, we can avoid a lot of calls to ->has_method, which is quite expensive. This seems to provide a speedup of approximately 10% when compiling Markdent::Simple::Document (and all the classes it loads in turn). --- diff --git a/lib/Class/MOP/Mixin/HasMethods.pm b/lib/Class/MOP/Mixin/HasMethods.pm index 8e38d5e..bc5b09c 100644 --- a/lib/Class/MOP/Mixin/HasMethods.pm +++ b/lib/Class/MOP/Mixin/HasMethods.pm @@ -149,7 +149,11 @@ sub remove_method { sub get_method_list { my $self = shift; - return grep { $self->has_method($_) } keys %{ $self->namespace }; + + my $namespace = $self->namespace; + + return grep { *{ $namespace->{$_} }{CODE} && $self->has_method($_) } + keys %{$namespace}; } 1;