Re: [Parseperl-discuss] Performance hacks
Brought to you by:
adamkennedy
From: Adam K. <ad...@ph...> - 2006-07-20 07:44:40
|
>> my $doc = PPI::Document->new( $something, >> readonly => 1, >> ); > > I was thinking something quite similar earlier today, but I couldn't > think of a good way to implement it without either 1) sprinkling "if > ($self->top->readonly)" everywhere, or 2) multiple inheritance or mixin > of a ::Mutable class for the non-readonly case. Agreed, actually checking it in every ->prune call would be onerous and slow things down, and doing some form of mutation or mixin for non-read-only seems infeasible without having entire seperate trees, tripling the number of classes. :/ > Wait, are you suggesting a global readonly flag, or a per-instance > readonly? It sounds like the former. I was instead thinking of the > latter. What I'm thinking is that we make ->readonly an advisory flag. If you create with ->readonly, then at least we (or anyone else) can know that the document as a whole is _intended_ to be readonly. We might not actually enforce it at the add_before level, but it can be checked in all sorts of places like PPI::Transform and so on, that deal with entire documents. It means at least anything that cares about readonly has the option to look for it. It also means we can then IN ADDITION to the advisory ->readonly attribute, we can implement a global ReadOnly mode to modify the function undef PPI::... Once that global ReadOnly is enabled, PPI::Document->new would simply die or return undef, and refuse to allow any document to be created that _doesn't_ have the ->readonly flag. So it would be a partly-cooperative, partly-enforced concept. Enforced at the per-document level, but cooperative at the per-element level. Because indeed doing ->top->readonly all over the place would be fairly hideous and slow things down (although we can look at adding it down the line). Adam K |