better table speedup

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_1_6@2148 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2001-06-27 16:28:56 +00:00
parent 3883c95207
commit 430ce1cc52
4 changed files with 31 additions and 17 deletions

View File

@ -1,3 +1,12 @@
2001-06-27 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* 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 <jug@sad.it> 2001-06-24 The LyX Project <jug@sad.it>
* src/lyxlex_pimpl.C (compare_tags): use compare_ascii_no_case instead * src/lyxlex_pimpl.C (compare_tags): use compare_ascii_no_case instead

View File

@ -1857,28 +1857,26 @@ int InsetTabular::GetMaxWidthOfCell(Painter &, int cell) const
int InsetTabular::getMaxWidth(Painter & pain, int InsetTabular::getMaxWidth(Painter & pain,
UpdatableInset const * inset) const UpdatableInset const * inset) const
{ {
typedef std::map<UpdatableInset const *, int> Cache; int cell = tabular->cur_cell;
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) { if (tabular->GetCellInset(cell) != inset) {
cell = actcell;
if (tabular->GetCellInset(cell) != inset) {
lyxerr << "Actcell not equal to actual cell!" << std::endl;
cell = -1; cell = -1;
} }
} }
int const n = tabular->GetNumberOfCells(); int const n = tabular->GetNumberOfCells();
if (cell == -1) { if (cell == -1) {
cell = 0; cell = 0;
for (; cell < n; ++cell) { for (; cell < n; ++cell) {
if (tabular->GetCellInset(cell) == inset) if (tabular->GetCellInset(cell) == inset)
break; break;
} }
cache[inset] = cell;
} }
if (cell >= n) if (cell >= n)
return -1; return -1;
int w = GetMaxWidthOfCell(pain, cell); int w = GetMaxWidthOfCell(pain, cell);

View File

@ -88,6 +88,7 @@ LyXTabular::columnstruct::columnstruct()
LyXTabular::LyXTabular(InsetTabular * inset, int rows_arg, int columns_arg) LyXTabular::LyXTabular(InsetTabular * inset, int rows_arg, int columns_arg)
{ {
owner_ = inset; owner_ = inset;
cur_cell = -1;
Init(rows_arg, columns_arg); 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) LyXTabular::LyXTabular(InsetTabular * inset, LyXTabular const & lt)
{ {
owner_ = inset; owner_ = inset;
cur_cell = -1;
Init(lt.rows_, lt.columns_); Init(lt.rows_, lt.columns_);
#ifdef WITH_WARNINGS #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) #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) LyXTabular::LyXTabular(Buffer const * buf, InsetTabular * inset, LyXLex & lex)
{ {
owner_ = inset; owner_ = inset;
cur_cell = -1;
Read(buf, lex); 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 // So then it is ok to throw an exception, or for now
// call abort() // call abort()
Assert(rows_ == lt.rows_ && columns_ == lt.columns_); Assert(rows_ == lt.rows_ && columns_ == lt.columns_);
cur_cell = -1;
cell_info = lt.cell_info; cell_info = lt.cell_info;
row_info = lt.row_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 InsetText * LyXTabular::GetCellInset(int cell) const
{ {
cur_cell = cell;
return & cell_info[row_of_cell(cell)][column_of_cell(cell)].inset; return & cell_info[row_of_cell(cell)][column_of_cell(cell)].inset;
} }

View File

@ -374,6 +374,8 @@ public:
InsetTabular * owner() const { return owner_; } InsetTabular * owner() const { return owner_; }
/// ///
void Validate(LaTeXFeatures &) const; void Validate(LaTeXFeatures &) const;
///
mutable int cur_cell;
private: ////////////////////////////////////////////////////////////////// private: //////////////////////////////////////////////////////////////////
/// ///