commit fc5b22a2f1009538abbfb335f2afe97ef16e433a
Author: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date:   Mon May 11 12:31:25 2020 +0200

    Get rid of lyx::next uses for RandomAccessList
    
    These uses are inefficient (a loop really) and require that pit_type
    is ptrdiff_t.
    
    Instead, RandomAccesslist::constIterator is renamed to iterator_at and
    a version adding a non-const iterator is added. Additionally, the
    method retirns end() when position is equal to the size of the
    container (see #11861).
    
    lyx::next and lyx::prev are removed, and std::prev is used in the few
    places where the code requires it (for no good reason IMO).
---
 src/Compare.cpp                |    4 ++--
 src/CutAndPaste.cpp            |   14 ++++++--------
 src/Text.cpp                   |   12 +++++-------
 src/Text2.cpp                  |    4 ++--
 src/Text3.cpp                  |    4 ++--
 src/output_docbook.cpp         |    4 ++--
 src/output_latex.cpp           |   18 +++++++++---------
 src/output_xhtml.cpp           |    4 ++--
 src/support/RandomAccessList.h |    9 +++++++--
 src/support/lyxalgo.h          |    5 -----
 10 files changed, 37 insertions(+), 41 deletions(-)

diff --git a/src/Compare.cpp b/src/Compare.cpp
index 60a0b65..68bd632 100644
--- a/src/Compare.cpp
+++ b/src/Compare.cpp
@@ -439,8 +439,8 @@ static void getParagraphList(DocRange const & range,
        pit_type startpit = range.from.pit();
        pit_type endpit = range.to.pit();
        ParagraphList const & ps_ = range.text()->paragraphs();
-       ParagraphList tmp_pars(lyx::next(ps_.begin(), startpit),
-               lyx::next(ps_.begin(), endpit + 1));
+       ParagraphList tmp_pars(ps_.iterator_at(startpit),
+               ps_.iterator_at(endpit + 1));
 
        // Remove the end of the last paragraph; afterwards, remove the
        // beginning of the first paragraph. Keep this order - there may only
diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp
index c8c084a..cfa69b5 100644
--- a/src/CutAndPaste.cpp
+++ b/src/CutAndPaste.cpp
@@ -462,17 +462,15 @@ pasteSelectionHelper(DocIterator const & cur, 
ParagraphList const & parlist,
 
        // Paste it!
        if (empty) {
-               pars.insert(lyx::next(pars.begin(), pit),
-                           insertion.begin(),
-                           insertion.end());
+               pars.insert(pars.iterator_at(pit),
+                           insertion.begin(), insertion.end());
 
                // merge the empty par with the last par of the insertion
                mergeParagraph(buffer.params(), pars,
                               pit + insertion.size() - 1);
        } else {
-               pars.insert(lyx::next(pars.begin(), pit + 1),
-                           insertion.begin(),
-                           insertion.end());
+               pars.insert(pars.iterator_at(pit + 1),
+                           insertion.begin(), insertion.end());
 
                // merge the first par of the insertion with the current par
                mergeParagraph(buffer.params(), pars, pit);
@@ -683,8 +681,8 @@ void copySelectionHelper(Buffer const & buf, Text const & 
text,
        LASSERT(startpit != endpit || start <= end, return);
 
        // Clone the paragraphs within the selection.
-       ParagraphList copy_pars(lyx::next(pars.begin(), startpit),
-                               lyx::next(pars.begin(), endpit + 1));
+       ParagraphList copy_pars(pars.iterator_at(startpit),
+                               pars.iterator_at(endpit + 1));
 
        // Remove the end of the last paragraph; afterwards, remove the
        // beginning of the first paragraph. Keep this order - there may only
diff --git a/src/Text.cpp b/src/Text.cpp
index 7c00a6a..2be5b86 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -113,8 +113,7 @@ void breakParagraphConservative(BufferParams const & 
bparams,
        ParagraphList & pars, pit_type pit, pos_type pos)
 {
        // create a new paragraph
-       Paragraph & tmp = *pars.insert(lyx::next(pars.begin(), pit + 1),
-                                      Paragraph());
+       Paragraph & tmp = *pars.insert(pars.iterator_at(pit + 1), Paragraph());
        Paragraph & par = pars[pit];
 
        tmp.setInsetOwner(&par.inInset());
@@ -169,7 +168,7 @@ void mergeParagraph(BufferParams const & bparams,
        // move the change of the end-of-paragraph character
        par.setChange(par.size(), change);
 
-       pars.erase(lyx::next(pars.begin(), par_offset + 1));
+       pars.erase(pars.iterator_at(par_offset + 1));
 }
 
 
@@ -691,8 +690,7 @@ static void breakParagraph(Text & text, pit_type 
par_offset, pos_type pos,
        ParagraphList & pars = text.paragraphs();
        // create a new paragraph, and insert into the list
        ParagraphList::iterator tmp =
-               pars.insert(lyx::next(pars.begin(), par_offset + 1),
-                           Paragraph());
+               pars.insert(pars.iterator_at(par_offset + 1), Paragraph());
 
        Paragraph & par = pars[par_offset];
 
@@ -1701,14 +1699,14 @@ bool Text::backspacePos0(Cursor & cur)
        if (cur.lastpos() == 0
            || (cur.lastpos() == 1 && par.isSeparator(0))) {
                cur.recordUndo(prevcur.pit());
-               plist.erase(lyx::next(plist.begin(), cur.pit()));
+               plist.erase(plist.iterator_at(cur.pit()));
                needsUpdate = true;
        }
        // is previous par empty?
        else if (prevcur.lastpos() == 0
                 || (prevcur.lastpos() == 1 && prevpar.isSeparator(0))) {
                cur.recordUndo(prevcur.pit());
-               plist.erase(lyx::next(plist.begin(), prevcur.pit()));
+               plist.erase(plist.iterator_at(prevcur.pit()));
                needsUpdate = true;
        }
        // FIXME: Do we really not want to allow this???
diff --git a/src/Text2.cpp b/src/Text2.cpp
index 6adbb51..2d1ca0e 100644
--- a/src/Text2.cpp
+++ b/src/Text2.cpp
@@ -917,7 +917,7 @@ bool Text::deleteEmptyParagraphMechanism(Cursor & cur,
                       min(old.pit() + 1, old.lastpit()));
        ParagraphList & plist = old.text()->paragraphs();
        bool const soa = oldpar.params().startOfAppendix();
-       plist.erase(lyx::next(plist.begin(), old.pit()));
+       plist.erase(plist.iterator_at(old.pit()));
        // do not lose start of appendix marker (bug 4212)
        if (soa && old.pit() < pit_type(plist.size()))
                plist[old.pit()].params().startOfAppendix(true);
@@ -989,7 +989,7 @@ void Text::deleteEmptyParagraphMechanism(pit_type first, 
pit_type last, bool tra
                        continue;
 
                if (par.empty() || (par.size() == 1 && par.isLineSeparator(0))) 
{
-                       pars_.erase(lyx::next(pars_.begin(), pit));
+                       pars_.erase(pars_.iterator_at(pit));
                        --pit;
                        --last;
                        continue;
diff --git a/src/Text3.cpp b/src/Text3.cpp
index f290ca6..238736b 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -384,7 +384,7 @@ static void outline(OutlineOp mode, Cursor & cur, Text * 
text)
        ParagraphList & pars = buf.text().paragraphs();
        ParagraphList::iterator const bgn = pars.begin();
        // The first paragraph of the area to be copied:
-       ParagraphList::iterator start = lyx::next(bgn, pit);
+       ParagraphList::iterator start = pars.iterator_at(pit);
        // The final paragraph of area to be copied:
        ParagraphList::iterator finish = start;
        ParagraphList::iterator const end = pars.end();
@@ -962,7 +962,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                ParagraphList & pars = buf.text().paragraphs();
                ParagraphList::iterator bgn = pars.begin();
                // The first paragraph of the area to be selected:
-               ParagraphList::iterator start = lyx::next(bgn, pit);
+               ParagraphList::iterator start = pars.iterator_at(pit);
                // The final paragraph of area to be selected:
                ParagraphList::iterator finish = start;
                ParagraphList::iterator end = pars.end();
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 6ed409c..a1a1889 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -329,8 +329,8 @@ void docbookParagraphs(Text const & text,
 
        // if only part of the paragraphs will be outputed
        if (runparams.par_begin !=  runparams.par_end) {
-               par = lyx::next(paragraphs.begin(), runparams.par_begin);
-               pend = lyx::next(paragraphs.begin(), runparams.par_end);
+               par = paragraphs.iterator_at(runparams.par_begin);
+               pend = paragraphs.iterator_at(runparams.par_end);
                // runparams will be passed to nested paragraphs, so
                // we have to reset the range parameters.
                const_cast<OutputParams&>(runparams).par_begin = 0;
diff --git a/src/output_latex.cpp b/src/output_latex.cpp
index 72a4577..f23fbda 100644
--- a/src/output_latex.cpp
+++ b/src/output_latex.cpp
@@ -383,7 +383,7 @@ void TeXEnvironment(Buffer const & buf, Text const & text,
                    pit_type & pit, otexstream & os)
 {
        ParagraphList const & paragraphs = text.paragraphs();
-       ParagraphList::const_iterator ipar = paragraphs.constIterator(pit);
+       ParagraphList::const_iterator ipar = paragraphs.iterator_at(pit);
        LYXERR(Debug::LATEX, "TeXEnvironment for paragraph " << pit);
 
        Layout const & current_layout = ipar->layout();
@@ -393,7 +393,7 @@ void TeXEnvironment(Buffer const & buf, Text const & text,
        // This is for debugging purpose at the end.
        pit_type const par_begin = pit;
        for (; pit < runparams.par_end; ++pit) {
-               ParagraphList::const_iterator par = 
paragraphs.constIterator(pit);
+               ParagraphList::const_iterator par = paragraphs.iterator_at(pit);
 
                // check first if this is an higher depth paragraph.
                bool go_out = (par->params().depth() < current_depth);
@@ -437,7 +437,7 @@ void TeXEnvironment(Buffer const & buf, Text const & text,
                // Do not output empty environments if the whole paragraph has
                // been deleted with ct and changes are not output.
                if (size_t(pit + 1) < paragraphs.size()) {
-                       ParagraphList::const_iterator nextpar = 
paragraphs.constIterator(pit + 1);
+                       ParagraphList::const_iterator nextpar = 
paragraphs.iterator_at(pit + 1);
                        Paragraph const & cpar = paragraphs.at(pit);
                        if ((par->layout() != nextpar->layout()
                             || par->params().depth() == 
nextpar->params().depth()
@@ -643,11 +643,11 @@ void latexArgInsets(ParagraphList const & pars,
        Layout const current_layout = pit->layout();
 
        // get the first paragraph in sequence with this layout and depth
-       pit_type offset = 0;
+       ptrdiff_t offset = 0;
        while (true) {
-               if (lyx::prev(pit, offset) == pars.begin())
+               if (prev(pit, offset) == pars.begin())
                        break;
-               ParagraphList::const_iterator priorpit = lyx::prev(pit, offset 
+ 1);
+               ParagraphList::const_iterator priorpit = prev(pit, offset + 1);
                if (priorpit->layout() == current_layout
                    && priorpit->params().depth() == current_depth)
                        ++offset;
@@ -655,7 +655,7 @@ void latexArgInsets(ParagraphList const & pars,
                        break;
        }
 
-       ParagraphList::const_iterator spit = lyx::prev(pit, offset);
+       ParagraphList::const_iterator spit = prev(pit, offset);
 
        for (; spit != pars.end(); ++spit) {
                if (spit->layout() != current_layout ||
@@ -1601,7 +1601,7 @@ void latexParagraphs(Buffer const & buf,
        bool gave_layout_warning = false;
        for (; pit < runparams.par_end; ++pit) {
                lastpit = pit;
-               ParagraphList::const_iterator par = 
paragraphs.constIterator(pit);
+               ParagraphList::const_iterator par = paragraphs.iterator_at(pit);
 
                // FIXME This check should not be needed. We should
                // perhaps issue an error if it is.
@@ -1660,7 +1660,7 @@ void latexParagraphs(Buffer const & buf,
                // Do not output empty environments if the whole paragraph has
                // been deleted with ct and changes are not output.
                if (size_t(pit + 1) < paragraphs.size()) {
-                       ParagraphList::const_iterator nextpar = 
paragraphs.constIterator(pit + 1);
+                       ParagraphList::const_iterator nextpar = 
paragraphs.iterator_at(pit + 1);
                        Paragraph const & cpar = paragraphs.at(pit);
                        if ((par->layout() != nextpar->layout()
                             || par->params().depth() == 
nextpar->params().depth()
diff --git a/src/output_xhtml.cpp b/src/output_xhtml.cpp
index c820c8a..469b316 100644
--- a/src/output_xhtml.cpp
+++ b/src/output_xhtml.cpp
@@ -1156,9 +1156,9 @@ void xhtmlParagraphs(Text const & text,
        OutputParams ourparams = runparams;
        ParagraphList::const_iterator const pend =
                (epit == (int) paragraphs.size()) ?
-                       paragraphs.end() : paragraphs.constIterator(epit);
+                       paragraphs.end() : paragraphs.iterator_at(epit);
        while (bpit < epit) {
-               ParagraphList::const_iterator par = 
paragraphs.constIterator(bpit);
+               ParagraphList::const_iterator par = 
paragraphs.iterator_at(bpit);
                if (par->params().startOfAppendix()) {
                        // We want to reset the counter corresponding to 
toplevel sectioning
                        Layout const & lay =
diff --git a/src/support/RandomAccessList.h b/src/support/RandomAccessList.h
index 2565d62..0eaa52a 100644
--- a/src/support/RandomAccessList.h
+++ b/src/support/RandomAccessList.h
@@ -294,9 +294,14 @@ public:
        }
 
 
-       const_iterator constIterator(size_t i) const
+       const_iterator iterator_at(size_t i) const
        {
-               return iterCont_[i];
+               return (i == size()) ? end() : iterCont_[i];
+       }
+
+       iterator iterator_at(size_t i)
+       {
+               return (i == size()) ? end() : iterCont_[i];
        }
 
 private:
diff --git a/src/support/lyxalgo.h b/src/support/lyxalgo.h
index d1aa023..8bf8bbc 100644
--- a/src/support/lyxalgo.h
+++ b/src/support/lyxalgo.h
@@ -84,11 +84,6 @@ void eliminate_duplicates(C & c)
 }
 
 
-using std::next;
-
-
-using std::prev;
-
 } // namespace lyx
 
 #endif // LYX_ALGO_H
-- 
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to