[Zope-Coders] Re: [ZPT] CVS: Zope/lib/python/ZTUtils - Tree.py:1.8

Jamie Heilman jamie@audible.transient.net
Fri, 4 Oct 2002 02:15:52 -0700


Jamie Heilman wrote:
> Yes I can hand you a bogus string of node id's and depth encodings,
> but by doing so, can I make anything bad happen?  If not, then
> testing only the first character should be more efficient.  If so,
> well then, lets fix it.

OK, I did some testing.  First, there's no magic behind the * operator.

        command            |  process size
        -------------------+--------------
        <at start>         |  2080K
        s='_'*1024*1024*4  |  6200K
        s == '_' * len(s)  |    10M

I used a 4M chunk so it would be a really obvious change and I could
be sure of what I was seeing.  Second, I beat up the ZTUtils
decodeExpansion function, and my version from ExpansionTree, with a
bunch of artifical expansion strings that didn't make any sense.  I
walked over the code watching what it would do if you handed it wonky
depths that made no sense, nothing but depth encodings, etc.  Apart
from generating a lot of unsightly execptions in the ZTUtils code, and
a corner case I'd missed in the ExpansionTree code, I couldn't figure
out a way to cause the routine to choke, eat its own tail, or do
anything else overly evil by feeding it bogus depth encodings.  As
such, I'd recommend only testing the first character as was previously
the case.

-- 
Jamie Heilman                   http://audible.transient.net/~jamie/
"We must be born with an intuition of mortality.  Before we know the words
 for it, before we know there are words, out we come bloodied and squalling
 with the knowledge that for all the compasses in the world, there's only
 one direction, and time is its only measure."		-Rosencrantz