[antlr-interest] Lazy load of CommonTokenStream??
Kay Röpke
kroepke at classdump.org
Sun Aug 17 12:44:50 PDT 2008
On Aug 17, 2008, at 9:13 PM, Jim Idle wrote:
>>
>> CommonTokenStream buffers all tokens up when it is first used.
>> Unfortunately, size() does not trigger filling the buffer which seems
>> like a bug. I see no reason why it shouldn't fill the buffer, that
>> is.
>
> I agree. In fact this might well be more intuitive, however we should
> think about any performance impact as this might be the reason it does
> not do this - in the C runtime I can take care of this by flipping
> functions after the first call, but you can't hack that in Java.
Not sure I understand what you are getting at.
fillBuffer() will set p = 0 when it is first called, thus getting the
size of the tokens calls fillBuffer() only once.
Actually all other methods that access tokens (with the notable
exception of get()) perform this check, too, so they all "suffer" from
that if.
Of course swizzling function pointers is more efficient in that sense,
you simply move the if out of the way :)
cheers,
-k
--
Kay Röpke
http://classdump.org/
More information about the antlr-interest
mailing list