From: Tokuhiro Matsuno Date: Thu, 2 Apr 2009 09:40:57 +0000 (+0900) Subject: use compiled type constraints. this change makes faster :) X-Git-Tag: 0.20~26 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=17d5fef423aff5e163749c4fc6c7e4356aee9cea;p=gitmo%2FMouse.git use compiled type constraints. this change makes faster :) --- diff --git a/lib/Mouse/Meta/Attribute.pm b/lib/Mouse/Meta/Attribute.pm index 9a16c11..0a262b7 100644 --- a/lib/Mouse/Meta/Attribute.pm +++ b/lib/Mouse/Meta/Attribute.pm @@ -74,6 +74,8 @@ sub generate_accessor { my $should_deref = $attribute->should_auto_deref; my $should_coerce = $attribute->should_coerce; + my $compiled_type_constraint = $constraint ? $constraint->{_compiled_type_constraint} : undef; + my $self = '$_[0]'; my $key = $attribute->inlined_name; @@ -97,12 +99,21 @@ sub generate_accessor { } else { $accessor .= $value.';'; } - $accessor .= - "\n". - '#line ' . __LINE__ . ' "' . __FILE__ . "\"\n" . - 'unless ($constraint->check($val)) { - $attribute->verify_type_constraint_error($name, $val, $attribute->{type_constraint}); - }' . "\n"; + if ($compiled_type_constraint) { + $accessor .= + "\n". + '#line ' . __LINE__ . ' "' . __FILE__ . "\"\n" . + 'unless ($compiled_type_constraint->($val)) { + $attribute->verify_type_constraint_error($name, $val, $attribute->{type_constraint}); + }' . "\n"; + } else { + $accessor .= + "\n". + '#line ' . __LINE__ . ' "' . __FILE__ . "\"\n" . + 'unless ($constraint->check($val)) { + $attribute->verify_type_constraint_error($name, $val, $attribute->{type_constraint}); + }' . "\n"; + } $value = '$val'; }