From: Dave Rolsky Date: Sun, 8 Aug 2010 08:58:32 +0000 (+0200) Subject: Inline the clone method in CMOP::Method as an optimization X-Git-Tag: 1.05~14 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0a3388ad28365536dd0896bfdbe9896a6e90430d;p=gitmo%2FClass-MOP.git Inline the clone method in CMOP::Method as an optimization --- diff --git a/lib/Class/MOP.pm b/lib/Class/MOP.pm index d4a2340..5e116a0 100644 --- a/lib/Class/MOP.pm +++ b/lib/Class/MOP.pm @@ -37,7 +37,6 @@ our $AUTHORITY = 'cpan:STEVAN'; require XSLoader; XSLoader::load( __PACKAGE__, $XS_VERSION ); - { # Metaclasses are singletons, so we cache them here. # there is no need to worry about destruction though @@ -549,13 +548,6 @@ Class::MOP::Method->meta->add_attribute( )) ); -Class::MOP::Method->meta->add_method('clone' => sub { - my $self = shift; - my $clone = $self->meta->clone_object($self, @_); - $clone->_set_original_method($self); - return $clone; -}); - ## -------------------------------------------------------- ## Class::MOP::Method::Wrapped diff --git a/lib/Class/MOP/Method.pm b/lib/Class/MOP/Method.pm index 64fb24e..7991de4 100644 --- a/lib/Class/MOP/Method.pm +++ b/lib/Class/MOP/Method.pm @@ -123,11 +123,19 @@ sub execute { $self->body->(@_); } -# NOTE: -# the Class::MOP bootstrap -# will create this for us -# - SL -# sub clone { ... } +# We used to go through use Class::MOP::Class->clone_instance to do this, but +# this was awfully slow. This method may be called a number of times when +# classes are loaded (especially during Moose role application), so it is +# worth optimizing. - DR +sub clone { + my $self = shift; + + my $clone = bless { %{$self}, @_ }, blessed($self); + + $clone->_set_original_method($self); + + return $clone; +} 1;