From: Tokuhiro Matsuno Date: Wed, 3 Dec 2008 03:05:13 +0000 (+0000) Subject: micro optimization X-Git-Tag: 0.19~136^2~77 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=41cdacce13ef9c29c2daabb92114572d15e762e5;p=gitmo%2FMouse.git micro optimization --- diff --git a/lib/Mouse/Meta/Method/Constructor.pm b/lib/Mouse/Meta/Method/Constructor.pm index 1786d4e..84d36ee 100644 --- a/lib/Mouse/Meta/Method/Constructor.pm +++ b/lib/Mouse/Meta/Method/Constructor.pm @@ -4,26 +4,33 @@ use warnings; sub generate_constructor_method_inline { my ($class, $meta) = @_; + my $code = $class->_generate_constructor_method_inline($meta); + warn $code if $ENV{DEBUG}; + + local $@; + my $res = eval $code; + die $@ if $@; + $res; +} + +sub _generate_constructor_method_inline { + my ($class, $meta) = @_; my $buildall = $class->_generate_BUILDALL($meta); my $buildargs = $class->_generate_BUILDARGS(); my $classname = $meta->name; my $processattrs = $class->_generate_processattrs($meta); - my $code = <<"..."; + return <<"..."; sub { my \$class = shift; my \$args = $buildargs; my \$instance = bless {}, '$classname'; + my \$meta = \$instance->meta; $processattrs; $buildall; return \$instance; } ... - warn $code if $ENV{DEBUG}; - - my $res = eval $code; - die $@ if $@; - $res; } sub _generate_processattrs { @@ -42,7 +49,9 @@ sub _generate_processattrs { push @code, "\$attr->verify_type_constraint( \$args->{\$from} );"; } push @code, "\$instance->{\$key} = \$args->{\$from};"; - push @code, "weaken( \$instance->{\$key} ) if ref( \$instance->{\$key} ) && \$attr->is_weak_ref;"; + if ($attr->is_weak_ref) { + push @code, "weaken( \$instance->{\$key} ) if ref( \$instance->{\$key} );"; + } if ( $attr->has_trigger ) { push @code, "\$attr->trigger->( \$instance, \$args->{\$from}, \$attr );"; } @@ -84,7 +93,7 @@ sub _generate_processattrs { }; my $code = <<"..."; { - my \$attr = \$instance->meta->get_attribute_map->{'$key'}; + my \$attr = \$meta->get_attribute('$key'); my \$from = '$from'; my \$key = '$key'; if (defined(\$from) && exists(\$args->{\$from})) {