Jean-Marc Lasgouttes a écrit :
"Abdelrazak" == Abdelrazak Younes <[EMAIL PROTECTED]> writes:

Abdelrazak> Maybe my code is wrong but I'd really like to know why.
Abdelrazak> All I am doing is saving the pointer in the table. The
Abdelrazak> second time a font that has the same characteristics is
Abdelrazak> required, instead of creating it again I pass the one
Abdelrazak> created before. So the contruction of a new font is
Abdelrazak> skipped.

I do not think the code is wrong, but it is not better than the old
one (and as Andre' said, it evaluates the array indices twice).
The old code is

        /// Get font info (font + metrics) for the given LyX font.
        QLFontInfo & fontinfo(LyXFont const & f) {
                QLFontInfo * & fi =
                        
fontinfo_[f.family()][f.series()][f.realShape()][f.size()];
                if (!fi)
                        fi = new QLFontInfo(f);
                return *fi;
        }

The "QLFontInfo * & fi" construct means that fi's address is the table
entry. Therefore, "fi = new QLFontInfo(f);" does set the entry in the
array.

So the trick was the '* &' instead of a simple '*'. I didn't know about that indeed and I actually _asked_ to the list what is the reason for the additional '&' but nobody answered. I am maybe stupid but this trick is not obvious to me. Besides, are you sure that this will work everywhere? It seems that there is an improvement under windows...

Abdelrazak> If the pointer retrieved in the table is equal to zero
Abdelrazak> that means that this particular font was not used before
Abdelrazak> and we have to create it (via new) and save its pointer to
Abdelrazak> the table.

Abdelrazak> The older code was doing nothing as the table was filled
Abdelrazak> with zero and was never filled in anywhere!

Do you have evidence that it does not? It may be that I read
the code wrong.

No it's me who didn't know about the '* &' trick.

[...]
The sluggishness of LyX/Qt 1.4 (wrt 1.3) is general, unfortunately.
Only the xforms frontend has reasonable performance.

Bennett profile results showed that part of the slowness is due to Qt4. Hence my try to optimize that.

JMarc

PS: looks like I am making you grumpy. It was not really intended.

Maybe I was a bit grumpy about you three saying that my code doesn't bringing anything without explaining why (you did now). I feel now a bit stupid and I hate that ;-)

Abdel.

Reply via email to