Martin Vermeer a écrit :
On Mon, 2006-04-03 at 14:44 +0200, Abdelrazak Younes wrote:
Is it the use of
needsUpdateCounters (should maybe be needsCountersUpdate) that helps?
Yes.
This is important. I suggest you create a minimal patch doing only this.
We test it, make sure it's OK, have it in, and continue from there.
I managed to find some time at the end... I have to quit this drug ;-)
Please find attached a patch that does just that; that is optimizing the
NO_LABEL and ITEMIZE cases for paragraph creation/deletion.
Jean-Marc, I think this is a good candidate for 1.4.1 or 1.4.2 as it is
not very intrusive and it helps a lot on big documents under windows.
Abdelrazak> The LABEL_ENUMERATE case optimization is not yet enabled
Abdelrazak> but is almost ready.
Yes, I see where you're going. But perhaps this is for a second patch
then. I love your enthusiasm, but we really have to do this carefully,
like the hedgehogs do it ;-)
Just send me a signal when you are ready to go further. ;-)
Abdel.
Index: buffer_funcs.C
===================================================================
--- buffer_funcs.C (revision 13538)
+++ buffer_funcs.C (working copy)
@@ -328,7 +328,6 @@
}
}
-
bool needEnumCounterReset(ParIterator const & it)
{
Paragraph const & par = *it;
@@ -345,6 +344,33 @@
return true;
}
+void setItemLabel(Paragraph & par)
+{
+ BOOST_ASSERT(par.layout()->labeltype == LABEL_ITEMIZE);
+
+ // At some point of time we should do something more
+ // clever here, like:
+ // par.params().labelString(
+ // bufparams.user_defined_bullet(par.itemdepth).getText());
+ // for now, use a simple hardcoded label
+ string itemlabel;
+ switch (par.itemdepth) {
+ case 0:
+ itemlabel = "*";
+ break;
+ case 1:
+ itemlabel = "-";
+ break;
+ case 2:
+ itemlabel = "@";
+ break;
+ case 3:
+ itemlabel = "·";
+ break;
+ }
+
+ par.params().labelString(itemlabel);
+}
// set the counter of a paragraph. This includes the labels
void setCounter(Buffer const & buf, ParIterator & it)
@@ -390,28 +416,9 @@
par.params().labelString(label);
}
} else if (layout->labeltype == LABEL_ITEMIZE) {
- // At some point of time we should do something more
- // clever here, like:
- // par.params().labelString(
- // bufparams.user_defined_bullet(par.itemdepth).getText());
- // for now, use a simple hardcoded label
- string itemlabel;
- switch (par.itemdepth) {
- case 0:
- itemlabel = "*";
- break;
- case 1:
- itemlabel = "-";
- break;
- case 2:
- itemlabel = "@";
- break;
- case 3:
- itemlabel = "·";
- break;
- }
- par.params().labelString(itemlabel);
+ setItemLabel(par);
+
} else if (layout->labeltype == LABEL_ENUMERATE) {
// FIXME
// Yes I know this is a really, really! bad solution
@@ -522,7 +529,30 @@
}
}
+bool needsUpdateCounters(size_t const pit, ParagraphList & pars,
+ Buffer const & buf)
+{
+ Paragraph & current_par = pars[pit];
+ switch (current_par.layout()->labeltype) {
+ // layout that has no label at all (ex: standard layout)
+ case LABEL_NO_LABEL:
+ return false;
+
+ // layout that has no label at all (ex: standard layout)
+ case LABEL_ITEMIZE:
+ setItemLabel(current_par);
+ return false;
+
+// case LABEL_ENUMERATE:
+// setEnumLabel(pit, pars, buf);
+// return false;
+
+ default:
+ return true;
+ }
+}
+
string expandLabel(Buffer const & buf,
LyXLayout_ptr const & layout, bool appendix)
{
Index: buffer_funcs.h
===================================================================
--- buffer_funcs.h (revision 13538)
+++ buffer_funcs.h (working copy)
@@ -13,6 +13,7 @@
#define BUFFER_FUNCS_H
#include "lyxlayout_ptr_fwd.h"
+#include "ParagraphList_fwd.h"
#include <string>
@@ -48,6 +49,14 @@
std::string expandLabel(Buffer const & buf, LyXLayout_ptr const & layout,
bool appendix);
+/// updates current counter and/or label if possible.
+/**
+\retval true if a full updateCounters is required.
+\retval false if a full updateCounters is not required.
+*/
+bool needsUpdateCounters(size_t const pit, ParagraphList & pars,
+ Buffer const & buf);
+
/// updates all counters
void updateCounters(Buffer const &);
Index: text.C
===================================================================
--- text.C (revision 13538)
+++ text.C (working copy)
@@ -1087,7 +1087,8 @@
while (!pars_[next_par].empty() && pars_[next_par].isNewline(0))
pars_[next_par].erase(0);
- updateCounters(cur.buffer());
+ if (needsUpdateCounters(next_par, pars_, cur.buffer()))
+ updateCounters(cur.buffer());
// Mark "carriage return" as inserted if change tracking:
if (cur.buffer().params().tracking_changes) {
@@ -1669,7 +1670,9 @@
--cur.pos();
// the counters may have changed
- updateCounters(cur.buffer());
+ if (needsUpdateCounters(cpit, pars_, cur.buffer()))
+ updateCounters(cur.buffer());
+
setCursor(cur, cur.pit(), cur.pos(), false);
}
return needsUpdate;