From: Dave Rolsky Date: Sun, 8 Aug 2010 09:14:02 +0000 (+0200) Subject: Some small optimizations to avoid repeated accessor calls when inlining a constructor X-Git-Tag: 1.05~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=63fc4b5a87a137612d8a1560d40972d512dd7517;p=gitmo%2FClass-MOP.git Some small optimizations to avoid repeated accessor calls when inlining a constructor --- diff --git a/lib/Class/MOP/Method/Constructor.pm b/lib/Class/MOP/Method/Constructor.pm index 48533f9..74912e7 100644 --- a/lib/Class/MOP/Method/Constructor.pm +++ b/lib/Class/MOP/Method/Constructor.pm @@ -145,20 +145,23 @@ sub _generate_slot_initializer { } if ( defined( my $init_arg = $attr->init_arg ) ) { + my $mi = $self->_meta_instance; + my $attr_name = $attr->name; + return ( 'if(exists $params->{\'' . $init_arg . '\'}){' . "\n" - . $self->_meta_instance->inline_set_slot_value( + . $mi->inline_set_slot_value( '$instance', - $attr->name, + $attr_name, '$params->{\'' . $init_arg . '\'}' ) . "\n" . '} ' . ( !defined $default ? '' : 'else {' . "\n" - . $self->_meta_instance->inline_set_slot_value( + . $mi->inline_set_slot_value( '$instance', - $attr->name, + $attr_name, $default ) . "\n" . '}'