sub initialize_instance_slot {
my ($self, $class, $instance, $params) = @_;
- # OPTIMIZATION NOTE:
- # We break the attribute encapsulation here
- # in order to save a number of method calls
- # to $self and speed things up a bit
my $init_arg = $self->{init_arg};
# try to fetch the init arg from the %params ...
my $val;
$val = $params->{$init_arg} if exists $params->{$init_arg};
# if nothing was in the %params, we can use the
# attribute's default value (if it has one)
- if (!defined $val && $self->{default}) {
+ if (!defined $val && defined $self->{default}) {
$val = $self->default($instance);
}
- $instance->{$self->{name}} = $val;
+ $instance->{$self->name} = $val;
}
# NOTE:
# Creation
-{
+#{
# Metaclasses are singletons, so we cache them here.
# there is no need to worry about destruction though
# because they should die only when the program dies.
$class_name . "->meta => (" . (blessed($meta)) . ")";
}
}
-}
+#}
sub create {
my ($class, $package_name, $package_version, %options) = @_;
(
$self->name,
map {
- $self->initialize($_)->class_precedence_list()
+ ($METAS{$_} || $self->initialize($_))->class_precedence_list()
} $self->superclasses()
);
}
my ($self, $attribute_name) = @_;
(defined $attribute_name && $attribute_name)
|| confess "You must define an attribute name";
- return $self->get_attribute_map->{$attribute_name}
- if $self->has_attribute($attribute_name);
+ # OPTIMIZATION NOTE:
+ # we used to say `if $self->has_attribute($attribute_name)`
+ # here, but since get_attribute is called so often, we
+ # eliminate the function call here
+ return $self->{'%:attributes'}->{$attribute_name}
+ if exists $self->{'%:attributes'}->{$attribute_name};
return;
}
sub get_attribute_list {
my $self = shift;
- keys %{$self->get_attribute_map};
+ # OPTIMIZATION NOTE:
+ # We don't use get_attribute_map here because
+ # we ask for the attribute list quite often
+ # in compute_all_applicable_attributes, so
+ # eliminating the function call helps
+ keys %{$self->{'%:attributes'}};
}
sub compute_all_applicable_attributes {
next if $seen_class{$class};
$seen_class{$class}++;
# fetch the meta-class ...
- my $meta = $self->initialize($class);
+ my $meta = ($METAS{$class} || $self->initialize($class));
foreach my $attr_name ($meta->get_attribute_list()) {
next if exists $seen_attr{$attr_name};
$seen_attr{$attr_name}++;