[antlr-interest] Re: ANTLR Java Code Generation
Christian Ernst
christian.ernst at poet.de
Wed Nov 14 02:54:01 PST 2001
Hy !
tom at psy.unsw.edu.au wrote:
> n*4. put -1L at n
> With all the extra loop overhead. Thus your time is now O[x*n] (where
> x is number of instructions to do for each entry). Is this actually
> going to be a gain? You still have to add the same number of entries.
1.Number of Entries:
Ther are less adds, because it is only done for all Members which are != 0L
see:
static long _tokenSet_0_data_[] = {0L,0L,0L,0L,1}
will be:
static long _tokenSet_0_data_[] = new long[5];
static{
_tokenSet_0_data_[4] = 1;
}
2. The extra Time for the Loop:
You could generate code without any Loop
like:
static{
_tokenSet_0_data_[0] = -1L;
_tokenSet_0_data_[1] = -1L;
_tokenSet_0_data_[2] = -1L;
_tokenSet_0_data_[3] = -1L;
}
But we asume that the Loop is the Element which is best optimized by JIT's
Another Solution might be the
Array.fill(long[],int,int,long)
But this means Method-Overhead and internaly yust the same Loop as we
did on our own.
> Just trades off class size vs. speed doesn't it. And I would have
> thought for many cases speed was more important than class size. You
> only store\load the class once, you have to do the BitSet creation
> every parse (if you did 2 passes with one init, then you'd double the
> amount of computation (and thus overhead) but same memory overhead).
3. BitSet initializing:
The initializing is done in a static block which is only executed once when
the Class is loaded
JAVAC is doing the same think with an array
static long _tokenSet_0_data_[] = {0L,0L,0L,0L,0L,-1L}
will be compiled as
static long _tokenSet_0_data_[] ;
static{
_tokenSet_0_data_[0] = 0L;
_tokenSet_0_data_[1] = 0L;
_tokenSet_0_data_[2] = 0L;
_tokenSet_0_data_[3] = 0L;
_tokenSet_0_data_[4] = -1L;
}
ther you can see also the 0L Problem...
> Tom.
mfg
Christian
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list