On Sun, Nov 08, 2009 at 11:54:42AM +0100, Abdelrazak Younes wrote:
> On 07/11/2009 00:35, Enrico Forestieri wrote:
> > On Fri, Nov 06, 2009 at 04:50:17PM +0100, Abdelrazak Younes wrote:
> >
> >
> >>> Modified: lyx-devel/trunk/src/mathed/MathMacroTemplate.h
> >>> ==============================================================================
> >>> + MathMacroTemplate(Buffer * buf = 0);
> >>>
> >> > Modified: lyx-devel/trunk/src/mathed/MathParser.h
> >> ==============================================================================
> >> > +bool mathed_parse_normal(MathAtom&, docstring const&,
> >> > + Parse::flags f = Parse::NORMAL, Buffer * buf = 0);
> >>
> >> Why the default buf to 0? Shouldn't we enforce that?
> >>
> >
> > In some parts of the code there is no way (that I know of) to get the
> > pointer to the buffer for which a MathHull inset is being created
> > (these are those corner cases I was speaking about). So what should
> > be the default? In those cases the buffer_ member is left 0, as it was
> > before this patch.
> >
>
> I am right now working on a patch to force Buffer passing in most
> InsetMath*.
>
> >
> >>> Modified: lyx-devel/trunk/src/mathed/MathParser.cpp
> >>> ==============================================================================
> >>>
> >>> -Parser::Parser(istream& is, parse_mode mode)
> >>> - : lineno_(0), pos_(0), mode_(mode), success_(true)
> >>> +Parser::Parser(istream& is, parse_mode mode, Buffer * buf)
> >>> + : lineno_(0), pos_(0), mode_(mode), success_(true), buffer_(buf)
> >>> {
> >>> + if (buf)
> >>> + buf->updateMacros();
> >>>
> >> Wouldn't this lead to performance problem at first load of a document
> >> with many macros? Ideally we only want to this once at file parsing and
> >> then each time a new macro is created.
> >>
> >
> > Yes, I was aware of this problem but don't know how to (easily) avoid it.
> > This call to updateMacros() is only needed at loading time, otherwise LyX
> > wouldn't know that a macro with a given name was already defined or not
> > by the user. One possibility that I took into account was tracking macro
> > creation in the parser itself. This would need adding a new std::set member
> > to the buffer (for example) in order to collect the macro names.
> > This would be fast, but then we would need a way to discriminate whether
> > the parser is called at loading time or not. Indeed, when checking for
> > the existence of a macro, we could simply check the std::set member at
> > loading time, but have to use getMacro() otherwise. This is because a
> > macro could be deleted later and getMacro() knows this. Hmmm... maybe
> > the std::set member could also be updated when that happens...
> > This definitely needs some more thinking... and time...
> >
> I see... But I guess this fix will be important for some users...
I did that and now the loading time is as it was before using updateMacros().
Not a great deal, though. A document with about 150 macros now loads in
about 3-4 seconds against about 5-6. However, in percentage that is a
40%-50% speedup, which could be significant for slow storage media.
--
Enrico