From: Matt S Trout Date: Fri, 5 Oct 2007 18:02:38 +0000 (+0000) Subject: minor optimisations to metaclass retrieval X-Git-Tag: 0_44~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3af3cbbd2b51fea6efda9e249d7589312c2ff81c;p=gitmo%2FClass-MOP.git minor optimisations to metaclass retrieval --- diff --git a/Changes b/Changes index ef5204a..8955b23 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for Perl extension Class-MOP. + * Class::MOP::Class + - optimise metaclass-already-exists check in construct_class_instance + - duplicate check into initialize to save a call through + 0.43 * Class::MOP::Method::Accessor - made this a subclass of Class::MOP::Method::Generated diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 83b4d1d..2c79d9c 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -29,6 +29,9 @@ sub initialize { my $package_name = shift; (defined $package_name && $package_name && !blessed($package_name)) || confess "You must pass a package name and it cannot be blessed"; + if (defined(my $meta = Class::MOP::get_metaclass_by_name($package_name))) { + return $meta; + } $class->construct_class_instance('package' => $package_name, @_); } @@ -58,8 +61,10 @@ sub construct_class_instance { # and it is still defined (it has not been # reaped by DESTROY yet, which can happen # annoyingly enough during global destruction) - return Class::MOP::get_metaclass_by_name($package_name) - if Class::MOP::does_metaclass_exist($package_name); + + if (defined(my $meta = Class::MOP::get_metaclass_by_name($package_name))) { + return $meta; + } # NOTE: # we need to deal with the possibility