perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeffrey W. Baker" <jwba...@acm.org>
Subject Re: Small Apache::Session improvement
Date Sat, 25 Mar 2000 15:30:06 GMT
On Fri, 24 Mar 2000, Adi wrote:

> Simon Rosenthal wrote:
> > 
> > b) An efficiency tweak in the STORE method for the tied hash ; we found we
> > were sometimes updating the session record unnecessarily  because we were
> > too lazy to  consistently write code like
> > 
> >         $sesshash{'foo'}  = 'bar' unless ($sesshash('foo'} eq  'bar).
> > 
> > so, since Laziness is  said to be a  virtue for Perl programmers, we
> > moved  that check into the STORE method.
> > 
> 
> I like this hack, but what if the data you're storing is not scalar?  Since
> Apache::Session supports multi-dimensional data structures using Manfredi's
> Storable module, what would happen if you do:
> 
> 	$sesshash{'foo'} = { 'bar' => 'baz' };
> 
> >From your code below, looks like it would try to compare the two scalar-ized
> HASHes such as:
> 
> 	if("HASH(0x80c8554)" ne "HASH(0x80c8554)") {
> 
> I'm not familiar enough with perl's innards to know if this produces the
> desired behaviour.  Can a hash ref that has been modified be stored in the
> SAME MEMORY LOCATION, and thus give identical values for $prev and $value? 
> If so, then your patch would lose data in these cases.

Actually the behavior is backward-compatible with existing Apache::Session
code.  My code already ignores changes that do not occur in the top level
hash.  This was both easy to right (sloth is a virtue), and fast at
runtime.  The module could be rewritten to do a "deep" data structure
comparison, but that would be both hard and slow.

-jwb


Mime
View raw message