Subject: | [PATCH] Roughly 15% speed increase for Class::Accessor::Fast |
use B 'perlstring';
sub make_accessor {
my ($class, $field) = @_;
eval sprintf q{
sub {
return $_[0]{%s} if scalar(@_) == 1;
return $_[0]{%s} = scalar(@_) == 2 ? $_[1] : [@_[1..$#_]];
}
}, map { perlstring($_) } $field, $field;
}
sub make_ro_accessor {
my($class, $field) = @_;
eval sprintf q{
sub {
return $_[0]{%s} if @_ == 1;
my $caller = caller;
$_[0]->_croak(sprintf "'$caller' cannot alter the value of '%%s' on objects of class '%%s'", %s, %s);
}
}, map { perlstring($_) } $field, $field, $class;
}
sub make_wo_accessor {
my($class, $field) = @_;
eval sprintf q{
sub {
if (@_ == 1) {
my $caller = caller;
$_[0]->_croak(sprintf "'$caller' cannot access the value of '%%s' on objects of class '%%s'", %s, %s);
}
else {
return $_[0]{%s} = $_[1] if @_ == 2;
return (shift)->{%s} = \@_;
}
}
}, map { perlstring($_) } $field, $class, $field, $field;
}