From: Yuval Kogman Date: Sun, 10 Aug 2008 16:39:07 +0000 (+0000) Subject: microoptimize Class::MOP::Class::initialize since it's called so often X-Git-Tag: 0_64_01~56 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=87715d2e8c8d3998753e6e792ea32be41dd2fafa;p=gitmo%2FClass-MOP.git microoptimize Class::MOP::Class::initialize since it's called so often --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 78d6051..c80b00c 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -19,18 +19,22 @@ use base 'Class::MOP::Module'; # Creation sub initialize { - my ( $class, @args ) = @_; - - unshift @args, 'package' if @args % 2 == 1; + my $class = shift; - my (%options) = @args; - my $package_name = $options{package}; + my $package_name; + + if ( @_ % 2 ) { + $package_name = shift; + } else { + my %options = @_; + $package_name = $options{package}; + } - (defined $package_name && $package_name && !blessed($package_name)) + (defined $package_name && $package_name && !ref($package_name)) || confess "You must pass a package name and it cannot be blessed"; return Class::MOP::get_metaclass_by_name($package_name) - || $class->construct_class_instance(%options); + || $class->construct_class_instance(package => $package_name, @_); } sub reinitialize {