From 430ce1cc52ab4c732abe9afe64a210fc00a5e33f Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Wed, 27 Jun 2001 16:28:56 +0000 Subject: [PATCH] better table speedup git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_1_6@2148 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 9 +++++++++ src/insets/insettabular.C | 32 +++++++++++++++----------------- src/tabular.C | 5 +++++ src/tabular.h | 2 ++ 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index a6ed3c5622..7e245f7a1b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2001-06-27 Jean-Marc Lasgouttes + + * src/insets/insettabular.C (getMaxWidth): do the speedup in a + different way, remove dead code + + * src/tabular.C (GetCellInset): store the last cell checked (gotten) + + * src/tabular.h: new member cur_cell, used to cache cell values. + 2001-06-24 The LyX Project * src/lyxlex_pimpl.C (compare_tags): use compare_ascii_no_case instead diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index e0ff2b01c0..07c59629a0 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -1857,28 +1857,26 @@ int InsetTabular::GetMaxWidthOfCell(Painter &, int cell) const int InsetTabular::getMaxWidth(Painter & pain, UpdatableInset const * inset) const { - typedef std::map Cache; - static Cache cache; - - int cell = -1; - Cache::const_iterator ci = cache.find(inset); - if (ci != cache.end()) { - cell = (*ci).second; - if (tabular->GetCellInset(cell) != inset) { - cell = -1; - } + int cell = tabular->cur_cell; + if (tabular->GetCellInset(cell) != inset) { + cell = actcell; + if (tabular->GetCellInset(cell) != inset) { + lyxerr << "Actcell not equal to actual cell!" << std::endl; + cell = -1; + } } - + int const n = tabular->GetNumberOfCells(); + if (cell == -1) { - cell = 0; - for (; cell < n; ++cell) { - if (tabular->GetCellInset(cell) == inset) - break; - } - cache[inset] = cell; + cell = 0; + for (; cell < n; ++cell) { + if (tabular->GetCellInset(cell) == inset) + break; + } } + if (cell >= n) return -1; int w = GetMaxWidthOfCell(pain, cell); diff --git a/src/tabular.C b/src/tabular.C index c9a2d2b5ba..ffbd347e37 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -88,6 +88,7 @@ LyXTabular::columnstruct::columnstruct() LyXTabular::LyXTabular(InsetTabular * inset, int rows_arg, int columns_arg) { owner_ = inset; + cur_cell = -1; Init(rows_arg, columns_arg); } @@ -95,6 +96,7 @@ LyXTabular::LyXTabular(InsetTabular * inset, int rows_arg, int columns_arg) LyXTabular::LyXTabular(InsetTabular * inset, LyXTabular const & lt) { owner_ = inset; + cur_cell = -1; Init(lt.rows_, lt.columns_); #ifdef WITH_WARNINGS #warning Jürgen, can you make it the other way round. So that copy assignment depends on the copy constructor and not the other way. (Lgb) @@ -106,6 +108,7 @@ LyXTabular::LyXTabular(InsetTabular * inset, LyXTabular const & lt) LyXTabular::LyXTabular(Buffer const * buf, InsetTabular * inset, LyXLex & lex) { owner_ = inset; + cur_cell = -1; Read(buf, lex); } @@ -116,6 +119,7 @@ LyXTabular & LyXTabular::operator=(LyXTabular const & lt) // So then it is ok to throw an exception, or for now // call abort() Assert(rows_ == lt.rows_ && columns_ == lt.columns_); + cur_cell = -1; cell_info = lt.cell_info; row_info = lt.row_info; @@ -3005,6 +3009,7 @@ int LyXTabular::Ascii(Buffer const * buf, ostream & os) const InsetText * LyXTabular::GetCellInset(int cell) const { + cur_cell = cell; return & cell_info[row_of_cell(cell)][column_of_cell(cell)].inset; } diff --git a/src/tabular.h b/src/tabular.h index c68ec96f31..27d58d3a81 100644 --- a/src/tabular.h +++ b/src/tabular.h @@ -374,6 +374,8 @@ public: InsetTabular * owner() const { return owner_; } /// void Validate(LaTeXFeatures &) const; + /// + mutable int cur_cell; private: ////////////////////////////////////////////////////////////////// ///