From: Dave Rolsky Date: Wed, 3 Dec 2008 00:16:46 +0000 (+0000) Subject: Make the type constraint classes immutable in X-Git-Tag: 0.62_01~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3cae4250365181ec0698335869b3dbb024117d18;p=gitmo%2FMoose.git Make the type constraint classes immutable in Moose::Util::TypeConstraints, just before we make a bunch of constaint objects for the recipe. This keeps us from calling the very slow MOP-based accessor methods while making these objects, which should speed up compilation a bit (at least it improves the profile ;) --- diff --git a/lib/Moose.pm b/lib/Moose.pm index ed4cf73..d733540 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -237,24 +237,18 @@ sub _get_caller { ## make 'em all immutable -$_->meta->make_immutable( +$_->make_immutable( inline_constructor => 1, constructor_name => "_new", - inline_accessors => 1, # these are Class::MOP accessors, so they need inlining - ) - for (qw( + # these are Class::MOP accessors, so they need inlining + inline_accessors => 1 + ) for grep { $_->is_mutable } + map { $_->meta } + qw( Moose::Meta::Attribute Moose::Meta::Class Moose::Meta::Instance - Moose::Meta::TypeConstraint - Moose::Meta::TypeConstraint::Union - Moose::Meta::TypeConstraint::Parameterized - Moose::Meta::TypeConstraint::Parameterizable - Moose::Meta::TypeConstraint::Enum - Moose::Meta::TypeConstraint::Class - Moose::Meta::TypeConstraint::Role - Moose::Meta::TypeConstraint::Registry Moose::Meta::TypeCoercion Moose::Meta::TypeCoercion::Union @@ -276,7 +270,7 @@ $_->meta->make_immutable( Moose::Meta::Role::Application::ToClass Moose::Meta::Role::Application::ToRole Moose::Meta::Role::Application::ToInstance -)); +); 1; diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index 6e3b4e0..b667d1b 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -481,6 +481,27 @@ sub _install_type_coercions ($$) { # define some basic built-in types ## -------------------------------------------------------- +# By making these classes immutable before creating all the types we +# below, we avoid repeatedly calling the slow MOP-based accessors. +$_->make_immutable( + inline_constructor => 1, + constructor_name => "_new", + + # these are Class::MOP accessors, so they need inlining + inline_accessors => 1 + ) for grep { $_->is_mutable } + map { $_->meta } + qw( + Moose::Meta::TypeConstraint + Moose::Meta::TypeConstraint::Union + Moose::Meta::TypeConstraint::Parameterized + Moose::Meta::TypeConstraint::Parameterizable + Moose::Meta::TypeConstraint::Class + Moose::Meta::TypeConstraint::Role + Moose::Meta::TypeConstraint::Enum + Moose::Meta::TypeConstraint::Registry +); + type 'Any' => where { 1 }; # meta-type including all type 'Item' => where { 1 }; # base-type