[EMAIL PROTECTED] (Lars Gullik Bjønnes) writes:

| I felt that the layout lookup became a bit slow with the new layout as
| string stuff, so I did this patch. Is the added complexity worth it?
| (I cleaned up the textclass a bit as well...)
>
| all lookup functions has changed from O(n) to O(log n)
| delete_layout is still O(n), but with a higer constant factor.
>
| but of course the lists are never very long, so the constant factor
| really plays a role here.

Some gprof statistics:

As in CVS now:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total
 time   seconds   seconds    calls  us/call  us/call  name
  7.70      0.56     0.56  2033932     0.28     0.41  std::__normal_iterator<LyXLayout 
const*, std::vector<LyXLayout, std::allocator<LyXLayout> > > 
std::find_if<std::__normal_iterator<LyXLayout const*, std::vector<LyXLayout, 
std::allocator<LyXLayout> > >, lyx::const_compare_memfun_t<std::string const&, 
LyXLayout, std::string> >(std::__normal_iterator<LyXLayout const*, 
std::vector<LyXLayout, std::allocator<LyXLayout> > >, std::__normal_iterator<LyXLayout 
const*, std::vector<LyXLayout, std::allocator<LyXLayout> > >, 
lyx::const_compare_memfun_t<std::string
const&, LyXLayout, std::string>, std::random_access_iterator_tag)
  6.74      1.05     0.49  4127140     0.12     0.12  
LyXFont::FontBits::operator==(LyXFont::FontBits const&) const
  5.78      1.47     0.42  1392143     0.30     0.98  
Paragraph::getFontSettings(BufferParams const&, int) const
  4.26      1.78     0.31  2031929     0.15     0.67  
LyXTextClass::operator[](std::string const&) const


With the patch below:

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total
 time   seconds   seconds    calls  us/call  us/call  name
  8.24      0.49     0.49  1394091     0.35     0.93  
Paragraph::getFontSettings(BufferParams const&, int) const
  5.21      0.80     0.31  4132035     0.08     0.08  
LyXFont::FontBits::operator==(LyXFont::FontBits const&) const
  4.54      1.07     0.27  5791950     0.05     0.05  Paragraph::Pimpl::getChar(int) 
const
  4.54      1.34     0.27  2033869     0.13     0.29  
LyXTextClass::operator[](std::string const&) const
......
  1.01      3.98     0.06   162549     0.37     0.42  std::__normal_iterator<LyXLayout 
const*, std::vector<LyXLayout, std::allocator<LyXLayout> > > 
std::find_if<std::__normal_iterator<LyXLayout const*, std::vector<LyXLayout, 
std::allocator<LyXLayout> > >, lyx::const_compare_memfun_t<std::string const&, 
LyXLayout, std::string> >(std::__normal_iterator<LyXLayout const*, 
std::vector<LyXLayout, std::allocator<LyXLayout> > >, std::__normal_iterator<LyXLayout 
const*, std::vector<LyXLayout, std::allocator<LyXLayout> > >, 
lyx::const_compare_memfun_t<std::string
const&, LyXLayout, std::string>, std::random_access_iterator_tag)


The patch:

Index: lyxtextclass.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtextclass.C,v
retrieving revision 1.9
diff -u -p -r1.9 lyxtextclass.C
--- lyxtextclass.C      12 Mar 2002 17:15:44 -0000      1.9
+++ lyxtextclass.C      12 Mar 2002 17:34:11 -0000
@@ -512,6 +512,13 @@ LyXLayout const & LyXTextClass::operator
                lyxerr << "Operator[] called with empty n" << endl;

        string const name = (n.empty() ? defaultLayoutName() : n);
+
+       static string lastLayoutName;
+       static LayoutList::difference_type lastLayoutIndex;
+
+       if (name == lastLayoutName)
+               return layoutlist[lastLayoutIndex];
+

        LayoutList::const_iterator cit =
                find_if(layoutlist.begin(),
@@ -527,6 +534,9 @@ LyXLayout const & LyXTextClass::operator
                lyx::Assert(false);
        }

+       lastLayoutName = name;
+       lastLayoutIndex = std::distance(layoutlist.begin(), cit);
+
        return *cit;
 }


-- 
        Lgb

Reply via email to