minor optimisations to metaclass retrieval
Matt S Trout [Fri, 5 Oct 2007 18:02:38 +0000 (18:02 +0000)]
Changes
lib/Class/MOP/Class.pm

diff --git a/Changes b/Changes
index ef5204a..8955b23 100644 (file)
--- 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
index 83b4d1d..2c79d9c 100644 (file)
@@ -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