From: Yuval Kogman Date: Tue, 29 Jan 2008 01:48:51 +0000 (+0000) Subject: microoptimization in Class::MOP::Instance X-Git-Tag: 0_53~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=230472a7d408d93238875666b1369406e8967de3;p=gitmo%2FClass-MOP.git microoptimization in Class::MOP::Instance --- diff --git a/lib/Class/MOP/Instance.pm b/lib/Class/MOP/Instance.pm index a19b4cb..3eae0c1 100644 --- a/lib/Class/MOP/Instance.pm +++ b/lib/Class/MOP/Instance.pm @@ -63,14 +63,14 @@ sub get_all_slots { sub is_valid_slot { my ($self, $slot_name) = @_; - exists $self->{'@!slots'}->{$slot_name} ? 1 : 0; + exists $self->{'@!slots'}->{$slot_name}; } # operations on created instances sub get_slot_value { my ($self, $instance, $slot_name) = @_; - $self->is_slot_initialized($instance, $slot_name) ? $instance->{$slot_name} : undef; + $instance->{$slot_name}; } sub set_slot_value { @@ -104,7 +104,7 @@ sub deinitialize_all_slots { sub is_slot_initialized { my ($self, $instance, $slot_name, $value) = @_; - exists $instance->{$slot_name} ? 1 : 0; + exists $instance->{$slot_name}; } sub weaken_slot_value { @@ -138,8 +138,7 @@ sub inline_slot_access { sub inline_get_slot_value { my ($self, $instance, $slot_name) = @_; - 'exists ' . $self->inline_slot_access($instance, $slot_name) . - ' ? ' . $self->inline_slot_access($instance, $slot_name) . ' : undef' + $self->inline_slot_access($instance, $slot_name); } sub inline_set_slot_value { @@ -158,7 +157,7 @@ sub inline_deinitialize_slot { } sub inline_is_slot_initialized { my ($self, $instance, $slot_name) = @_; - "exists " . $self->inline_slot_access($instance, $slot_name) . " ? 1 : 0"; + "exists " . $self->inline_slot_access($instance, $slot_name); } sub inline_weaken_slot_value { diff --git a/t/061_instance_inline.t b/t/061_instance_inline.t index ec35302..075d960 100644 --- a/t/061_instance_inline.t +++ b/t/061_instance_inline.t @@ -18,7 +18,7 @@ my $C = 'Class::MOP::Instance'; my $value = '$value'; is($C->inline_get_slot_value($instance, $slot_name), - 'exists $self->{"foo"} ? $self->{"foo"} : undef', + '$self->{"foo"}', '... got the right code for get_slot_value'); is($C->inline_set_slot_value($instance, $slot_name, $value), @@ -30,7 +30,7 @@ my $C = 'Class::MOP::Instance'; '... got the right code for initialize_slot'); is($C->inline_is_slot_initialized($instance, $slot_name), - 'exists $self->{"foo"} ? 1 : 0', + 'exists $self->{"foo"}', '... got the right code for get_slot_value'); is($C->inline_weaken_slot_value($instance, $slot_name), @@ -48,7 +48,7 @@ my $C = 'Class::MOP::Instance'; my $value = '[]'; is($C->inline_get_slot_value($instance, $slot_name), - 'exists $_[0]->{$attr_name} ? $_[0]->{$attr_name} : undef', + '$_[0]->{$attr_name}', '... got the right code for get_slot_value'); is($C->inline_set_slot_value($instance, $slot_name, $value), @@ -60,7 +60,7 @@ my $C = 'Class::MOP::Instance'; '... got the right code for initialize_slot'); is($C->inline_is_slot_initialized($instance, $slot_name), - 'exists $_[0]->{$attr_name} ? 1 : 0', + 'exists $_[0]->{$attr_name}', '... got the right code for get_slot_value'); is($C->inline_weaken_slot_value($instance, $slot_name), @@ -81,7 +81,7 @@ my $accessor_string = "sub {\n" is($accessor_string, q|sub { $_[0]->{$attr_name} = $_[1] if scalar @_ == 2; -exists $_[0]->{$attr_name} ? $_[0]->{$attr_name} : undef; +$_[0]->{$attr_name}; }|, '... got the right code string for accessor'); @@ -91,7 +91,7 @@ my $reader_string = "sub {\n" is($reader_string, q|sub { -exists $_[0]->{$attr_name} ? $_[0]->{$attr_name} : undef; +$_[0]->{$attr_name}; }|, '... got the right code string for reader');