Acme::SvGROW - syntax for pre-extending a string's storage,


Acme-SvGROW documentation Contained in the Acme-SvGROW distribution.

Index


Code Index:

NAME

Top

Acme::SvGROW - syntax for pre-extending a string's storage, like the proposed use of length as an L-value

SYNOPSIS

Top

  use Acme::SvGROW;
  SvGrow($BigString, 100000);
  # when l-value subroutines are available (5.8 and later)
  SvGrow($BigString, 100000) = InitialValueOfBigString();

DESCRIPTION

Top

Trivial module implementing string storage preallocation using techniques shared on perl5-porters mailing list November 4 and 5, 2009

EXPORT

Top

the SvGROW subroutine is exported. It takes two arguments, the first the string to extend and the second the length.

SEE ALSO

Top

perlguts

Data::Peek for a benchmarking of the alternatives

The author of this module is in favor of allowing length to be used as an lvalue to thinly invoke the SvGROW internals macro

CHANGES

Top

0.03

Data::Peek::DGrow will be used if available

AUTHOR

Top

David Nicol davidnico@cpan.org

COPYRIGHT AND LICENSE

Top


Acme-SvGROW documentation Contained in the Acme-SvGROW distribution.

package Acme::SvGROW;

require Exporter;
@ISA = qw(Exporter);

@EXPORT = qw(
	SvGROW	
);

$VERSION = '0.03';
if (eval <<'dgrowp'
   use Data::Peek 'DGrow';
   1;
dgrowp
){
   eval <<'LVAL' or eval <<'NOLVAL' or die "DGrow sub failed: $@"

     sub SvGROW($$) : lvalue {
        DGrow($_[0],$_[1]);
        $_[0]
     }
     1;
LVAL

     sub SvGROW($$) {
        DGrow($_[0],$_[1]);
        $_[0]
     }
NOLVAL

}
else
{
   eval <<'LVAL' or eval <<'NOLVAL'

     sub SvGROW($$) : lvalue {
        my $tmp = $_[0];
        $_[0] = pack 'x'.int(0+$_[1]);
        $_[0] = $tmp;
        $_[0]
     }
     1;
LVAL

     sub SvGROW($$) {
        my $tmp = $_[0];
        $_[0] = pack 'x'.int(0+$_[1]);
        $_[0] = $tmp;
        $_[0]
     }
NOLVAL

};

1;
__END__