[EMAIL PROTECTED] writes:

| Author: sts
| Date: Thu May 24 18:29:40 2007
| New Revision: 18489
| 
| URL: http://www.lyx.org/trac/changeset/18489
| Log:
| * do not lookup the same macro all the time
| * only update the representation if anything was changed (this gives a
|   huge speedup), fixes #2452
| * minor cleanup of the code, especially setting up the coordinate
|   cache. Without this can lead to crashes if the macros do not mention
|   all the arguments. 
| * And a last fix included makes sure that the metrics are always in
|   sync with the drawing. Before it was possible to go into the macro
|   with the cursor in a way that the metrics were for the viewing mode,
|   but the drawing was done for editing.
| 
| Modified:
|     lyx-devel/trunk/src/mathed/MacroTable.h
|     lyx-devel/trunk/src/mathed/MathMacro.cpp
|     lyx-devel/trunk/src/mathed/MathMacro.h
| 
| Modified: lyx-devel/trunk/src/mathed/MacroTable.h
| URL: 
http://www.lyx.org/trac/file/lyx-devel/trunk/src/mathed/MacroTable.h?rev=18489
| ==============================================================================
| --- lyx-devel/trunk/src/mathed/MacroTable.h (original)
| +++ lyx-devel/trunk/src/mathed/MacroTable.h Thu May 24 18:29:40 2007
| @@ -49,6 +49,16 @@
|       ///
|       void unlock() const { --lockCount_; BOOST_ASSERT(lockCount_ >= 0); }    
|  
| +     ///
| +     bool operator==(MacroData const & x) const {
| +             return def_ == x.def_ &&
| +                     numargs_ == x.numargs_ &&
| +                     disp_ == x.disp_ &&
| +                     requires_ == x.requires_;
| +     }
| +     ///
| +     bool operator!=(MacroData const & x) const { return !operator==(x); }

It is preferrable to have binary operators out-of-class. Make them
friends if they have to access private data.

bool operator==(MacroData const & lhs, MacroData const & rhs)
{
        return lhs.def_ == rhs.def_ &&
               lhs.numargs_ == rhs.numargs_ &&
               lhs.disp_ == rhs.disp_ &&
               lhs.requires_ == rhs.requires_;
}

And then != gets nicer as well:

bool operator!=(MacroData const & lhs, MacroData const & rhs)
{
        return !(lhs == rhs);
}

| Modified: lyx-devel/trunk/src/mathed/MathMacro.cpp
| URL: 
http://www.lyx.org/trac/file/lyx-devel/trunk/src/mathed/MathMacro.cpp?rev=18489
| ==============================================================================
| --- lyx-devel/trunk/src/mathed/MathMacro.cpp (original)
| +++ lyx-devel/trunk/src/mathed/MathMacro.cpp Thu May 24 18:29:40 2007
| @@ -75,20 +76,24 @@
|  void MathMacroArgumentValue::draw(PainterInfo & pi, int x, int y) const 
|  {
|       // unlock outer macro in arguments, and lock it again later
| -     MacroTable::globalMacros().get(macroName_).unlock();
| -     value_->draw(pi, x, y);
| -     MacroTable::globalMacros().get(macroName_).lock();
| +     MacroData const & macro = 
MacroTable::globalMacros().get(mathMacro_.name());
| +     macro.unlock();
| +     mathMacro_.cell(idx_).draw(pi, x, y);
| +     macro.lock();
|  }
|  
|  
|  MathMacro::MathMacro(docstring const & name, int numargs)
| -     : InsetMathNest(numargs), name_(name)
| +     : InsetMathNest(numargs), name_(name), editing_(false)
|  {}
|  
|  
|  auto_ptr<Inset> MathMacro::doClone() const
|  {
| -     return auto_ptr<Inset>(new MathMacro(*this));
| +     MathMacro * x = new MathMacro(*this);
| +     x->expanded_ = MathData();
| +     x->macroBackup_ = MacroData();
| +     return auto_ptr<Inset>(x);
|  }

Put new pointer into smart pointer as very first thing. Better
defensive programming.

-- 
        Lgb

Reply via email to