Skip Menu |

This queue is for tickets about the Class-Accessor CPAN distribution.

Report information
The Basics
Id: 84838
Status: resolved
Priority: 0/
Queue: Class-Accessor

People
Owner: jonasbn [...] cpan.org
Requestors: perl [...] toby.ink
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.34
Fixed in: 0.50



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; }
PR created on GIthub https://github.com/maokt/class-accessor-pm/pull/5 jonasbn On Wed Apr 24 16:02:23 2013, TOBYINK wrote: Show quoted text
> 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; > }
This has been addressed in release 0.50 Thank you, jonasbn