From: Jarkko Hietaniemi Date: Fri, 29 Mar 2002 18:34:27 +0000 (+0000) Subject: Upgrade to Memoize 1.00, from mjd, modulo the Memoize::Saves, X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5189e6feed9c4945d8abd4abe4d194bcee21856d;p=p5sagit%2Fp5-mst-13.2.git Upgrade to Memoize 1.00, from mjd, modulo the Memoize::Saves, which one has to get from the CPAN distribution. p4raw-id: //depot/perl@15614 --- diff --git a/MANIFEST b/MANIFEST index a300427..f1c0bd6 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1168,9 +1168,9 @@ lib/Memoize/t/array_confusion.t Memoize lib/Memoize/t/correctness.t Memoize lib/Memoize/t/errors.t Memoize lib/Memoize/t/expire.t Memoize -lib/Memoize/t/expire_file.t Memoize -lib/Memoize/t/expire_module_n.t Memoize -lib/Memoize/t/expire_module_t.t Memoize +lib/Memoize/t/expfile.t Memoize +lib/Memoize/t/expmod_n.t Memoize +lib/Memoize/t/expmod_t.t Memoize lib/Memoize/t/flush.t Memoize lib/Memoize/t/normalize.t Memoize lib/Memoize/t/prototype.t Memoize diff --git a/lib/Memoize.pm b/lib/Memoize.pm index 6907400..9f5c591 100644 --- a/lib/Memoize.pm +++ b/lib/Memoize.pm @@ -8,10 +8,10 @@ # same terms as Perl itself. If in doubt, # write to mjd-perl-memoize+@plover.com for a license. # -# Version 0.66 $Revision: 1.18 $ $Date: 2001/06/24 17:16:47 $ +# Version 1.00 $Revision: 1.18 $ $Date: 2001/06/24 17:16:47 $ package Memoize; -$VERSION = '0.66'; +$VERSION = '1.00'; # Compile-time constants sub SCALAR () { 0 } @@ -167,6 +167,8 @@ sub memoize { $wrapper # Return just memoized version } +use warnings::register; + # This function tries to load a tied hash class and tie the hash to it. sub _my_tie { my ($context, $hash, $options) = @_; @@ -176,8 +178,8 @@ sub _my_tie { my $shortopt = (ref $fullopt) ? $fullopt->[0] : $fullopt; return unless defined $shortopt && $shortopt eq 'TIE'; - carp("TIE option to memoize() is deprecated; use HASH instead") if $^W; - + carp("TIE option to memoize() is deprecated; use HASH instead") + if warnings::enabled('deprecated'); my @args = ref $fullopt ? @$fullopt : (); shift @args; @@ -357,10 +359,11 @@ sub _crap_out { =head1 NAME -Memoize - Make your functions faster by trading space for time +Memoize - Make functions faster by trading space for time =head1 SYNOPSIS + # This is the documentation for Memoize 1.00 use Memoize; memoize('slow_function'); slow_function(arguments); # Is faster than it was before @@ -462,7 +465,7 @@ this: Since there are relatively few objects in a picture, there are only a few colors, which get looked up over and over again. Memoizing -C speeded up the program by several percent. +C sped up the program by several percent. =head1 DETAILS @@ -692,15 +695,18 @@ because all its results have been precomputed. =item C -This option is B and will be removed -in the B release of C. Use the C option instead. +This option is no longer supported. It is still documented only to +aid in the debugging of old programs that use it. Old programs should +be converted to use the C option instead. memoize ... [TIE, PACKAGE, ARGS...] is merely a shortcut for require PACKAGE; - tie my %cache, PACKAGE, ARGS...; + { my %cache; + tie %cache, PACKAGE, ARGS...; + } memoize ... [HASH => \%cache]; =item C @@ -975,15 +981,12 @@ in Perl, and until it is resolved, memoized functions will see a slightly different C and will perform a little more slowly on threaded perls than unthreaded perls. -Here's a bug that isn't my fault: Some versions of C won't -let you store data under a key of length 0. That means that if you -have a function C which you memoized and the cache is in a -C database, then the value of C (C called with no -arguments) will not be memoized. Let us all breathe deeply and repeat -this mantra: ``Gosh, Keith, that sure was a stupid thing to do.'' If -this is a big problem, you can write a tied hash class which is a -front-end to C that prepends to every key before storing -it. +Some versions of C won't let you store data under a key of +length 0. That means that if you have a function C which you +memoized and the cache is in a C database, then the value of +C (C called with no arguments) will not be memoized. If this +is a big problem, you can supply a normalizer function that prepends +C<"x"> to every key. =head1 MAILING LIST diff --git a/lib/Memoize/Expire.pm b/lib/Memoize/Expire.pm index b3ab10a..97e1aa4 100644 --- a/lib/Memoize/Expire.pm +++ b/lib/Memoize/Expire.pm @@ -3,7 +3,7 @@ package Memoize::Expire; # require 5.00556; use Carp; $DEBUG = 0; -$VERSION = '0.66'; +$VERSION = '1.00'; # This package will implement expiration by prepending a fixed-length header # to the font of the cached data. The format of the header will be: @@ -311,15 +311,10 @@ the underlying cache so that the user can specify that the cache is also persistent or that it has some other interesting semantics. The example above demonstrates how to do this, as does C. -Another sample module, C, is included with this -package. It implements a policy that allows you to specify that -certain function values whould always be looked up afresh. See the -documentation for details. - =head1 ALTERNATIVES Brent Powers has a C module that was designed to -wotk with Memoize and provides expiration of least-recently-used data. +work with Memoize and provides expiration of least-recently-used data. The cache is held at a fixed number of entries, and when new data comes in, the least-recently used data is expired. See L. diff --git a/lib/Memoize/README b/lib/Memoize/README index b7abb5f..552f621 100644 --- a/lib/Memoize/README +++ b/lib/Memoize/README @@ -1,7 +1,7 @@ Name: Memoize What: Transparently speed up functions by caching return values. -Version: 0.66 +Version: 1.00 Author: Mark-Jason Dominus (mjd-perl-memoize+@plover.com) ################################################################ @@ -25,6 +25,11 @@ If not, please send me a report that mentions which tests failed. The address is: mjd-perl-memoize+@plover.com. ################################################################ +What's new since 0.66: + +Minor documentation and test changes only. + +################################################################ What's new since 0.65: Test changes only. diff --git a/lib/Memoize/t/expire_file.t b/lib/Memoize/t/expfile.t similarity index 89% rename from lib/Memoize/t/expire_file.t rename to lib/Memoize/t/expfile.t index 78a94d4..9959d00 100644 --- a/lib/Memoize/t/expire_file.t +++ b/lib/Memoize/t/expfile.t @@ -1,9 +1,6 @@ #!/usr/bin/perl -BEGIN { - chdir 't' if -d 't'; - @INC = '../lib'; -} +use lib '..'; use Memoize; my $n = 0; @@ -31,7 +28,7 @@ sub writefile { sub readfile { $READFILE_CALLS++; my $FILE = shift; - open F, "< $FILE" or die "Couldn't read temporary file $FILE: $!"; + open F, "< $FILE" or die "Couldn't write temporary file $FILE: $!"; my $data = ; close F; $data; @@ -61,7 +58,7 @@ my $t2 = readfile($FILE); ++$n; print ((($READFILE_CALLS == 1) ? '' : 'not '), "ok $n\n"); ++$n; print ((($t1 eq $t2) ? '' : 'not '), "ok $n\n"); -sleep 3; +sleep 2; writefile($FILE); my $t3 = readfile($FILE); ++$n; print "ok $n\n"; diff --git a/lib/Memoize/t/expire_module_n.t b/lib/Memoize/t/expmod_n.t similarity index 95% rename from lib/Memoize/t/expire_module_n.t rename to lib/Memoize/t/expmod_n.t index e88d2ec..7e5505a 100644 --- a/lib/Memoize/t/expire_module_n.t +++ b/lib/Memoize/t/expmod_n.t @@ -1,9 +1,6 @@ #!/usr/bin/perl -BEGIN { - chdir 't' if -d 't'; - @INC = '../lib'; -} +use lib '..'; use Memoize; my $n = 0; diff --git a/lib/Memoize/t/expire_module_t.t b/lib/Memoize/t/expmod_t.t similarity index 97% rename from lib/Memoize/t/expire_module_t.t rename to lib/Memoize/t/expmod_t.t index 73b3f08..3cc3de1 100644 --- a/lib/Memoize/t/expire_module_t.t +++ b/lib/Memoize/t/expmod_t.t @@ -1,9 +1,6 @@ #!/usr/bin/perl -BEGIN { - chdir 't' if -d 't'; - @INC = '../lib'; -} +use lib '..'; use Memoize; BEGIN { eval {require Time::HiRes};