Paragraph::needsCProtection(): use inset list

rather than checking each pos whether it's an inset or not.

This was a significant performance bottleneck (particularly getInset()
itself seems slow).
This commit is contained in:
Juergen Spitzmueller 2021-12-19 15:39:49 +01:00
parent a3fd3a09f1
commit 61b8afd893

View File

@ -4108,15 +4108,14 @@ bool Paragraph::needsCProtection(bool const fragile) const
} }
// now check whether we have insets that need cprotection // now check whether we have insets that need cprotection
pos_type size = pos_type(d->text_.size()); for (auto const & icit : d->insetlist_) {
for (pos_type i = 0; i < size; ++i) { Inset const * ins = icit.inset;
if (!isInset(i)) if (!ins)
continue; continue;
Inset const * ins = getInset(i);
if (ins->needsCProtection(maintext, fragile)) if (ins->needsCProtection(maintext, fragile))
return true; return true;
// Now check math environments // Now check math environments
InsetMath const * im = getInset(i)->asInsetMath(); InsetMath const * im = ins->asInsetMath();
if (!im || im->cell(0).empty()) if (!im || im->cell(0).empty())
continue; continue;
switch(im->cell(0)[0]->lyxCode()) { switch(im->cell(0)[0]->lyxCode()) {