]> git.lyx.org Git - features.git/commitdiff
* undo_funcs.C:
authorAndré Pönitz <poenitz@gmx.net>
Fri, 2 May 2003 13:11:39 +0000 (13:11 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 2 May 2003 13:11:39 +0000 (13:11 +0000)
  * undo.[Ch]: rely on std::vector<Paragraph *> instead of manually
    linked lists

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6923 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/undo.C
src/undo.h
src/undo_funcs.C

index fec14f53be9dfc5c36282ca086eccc33471277b9..c5e30142eea497e23423476c3133ad96fd18b379 100644 (file)
@@ -1,7 +1,11 @@
 
 2003-05-02 André Pönitz <poenitz@gmx.net>
 
-       * buffer.[Ch]: two instances of Paragraph * ->  ParagraphList::iterator
+       * buffer.[Ch]: two instances of Paragraph * -> ParagraphList::iterator
+
+       * undo_funcs.C:
+       * undo.[Ch]: rely on std::vector<Paragraph *> instead of manually
+         linked lists
 
 2003-05-02  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
index 1d304038826a42cf63dd8c61c9122065efd4ae13..9b093e41ed4b88b6cd5e4012926904b63198bf1b 100644 (file)
@@ -17,7 +17,8 @@
 Undo::Undo(undo_kind kind_arg, int id_inset_arg,
           int number_before_arg, int number_behind_arg,
           int cursor_par_arg, int cursor_pos_arg,
-          Paragraph * par_arg)
+          std::vector<Paragraph *> const & par_arg)
+       : pars(par_arg)
 {
        kind = kind_arg;
        number_of_inset_id = id_inset_arg;
@@ -25,16 +26,13 @@ Undo::Undo(undo_kind kind_arg, int id_inset_arg,
        number_of_behind_par = number_behind_arg;
        number_of_cursor_par = cursor_par_arg;
        cursor_pos = cursor_pos_arg;
-       par = par_arg;
 }
 
 
 Undo::~Undo()
 {
-       Paragraph * tmppar;
-       while (par) {
-               tmppar = par;
-               par = par->next();
-               delete tmppar;
-       }
+       std::vector<Paragraph *>::iterator it = pars.begin();
+       std::vector<Paragraph *>::iterator end = pars.end();
+       for ( ; it != end; ++it)
+               delete *it;
 }
index 4abd779396772d876ab4d6a965495dfcc4a7b3ff..19fb2d13631f4b35c5fa028fb72117b89fce478f 100644 (file)
@@ -12,6 +12,8 @@
 #ifndef UNDO_H
 #define UNDO_H
 
+#include <vector>
+
 class Paragraph;
 
 ///
@@ -41,12 +43,12 @@ public:
        ///
        int cursor_pos; // valid if >= 0
        ///
-       Paragraph * par;
+       std::vector<Paragraph *> pars;
        ///
        Undo(undo_kind kind_arg, int id_inset_arg,
             int number_before_arg, int number_behind_arg,
             int cursor_par_arg, int cursor_pos_arg,
-            Paragraph * par_arg);
+            std::vector<Paragraph *> const & par_arg);
        ///
        ~Undo();
 };
index 0765fb501d72fe5df6b2f3c7e4079a24b209e610..c484bc5fdc974e07834c3cd1f9b7dcc85e97ee27 100644 (file)
@@ -99,10 +99,10 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
 
        // Replace the paragraphs with the undo informations.
 
-       Paragraph * undopar = undo.par;
+       Paragraph * undopar = undo.pars.empty() ? 0 : undo.pars[0];
        // Otherwise the undo destructor would
        // delete the paragraph.
-       undo.par = 0;
+       undo.pars.resize(0);
 
        // Get last undo par and set the right(new) inset-owner of the
        // paragraph if there is any. This is not needed if we don't
@@ -325,7 +325,7 @@ bool createUndo(BufferView * bv, Undo::undo_kind kind,
        }
 
        // Create a new Undo.
-       Paragraph * undopar = 0;
+       std::vector<Paragraph *> undo_pars;
 
        Paragraph * start = first;
        Paragraph * end = 0;
@@ -342,29 +342,27 @@ bool createUndo(BufferView * bv, Undo::undo_kind kind,
                 ((before_number < 0) && (behind_number < 0))))
        {
                Paragraph * tmppar = start;
-               Paragraph * tmppar2 = new Paragraph(*tmppar, true);
+               undo_pars.push_back(new Paragraph(*tmppar, true));
 
                // A memory optimization: Just store the layout
                // information when only edit.
                if (kind == Undo::EDIT) {
-                       tmppar2->clearContents();
+                       undo_pars.back()->clearContents();
                }
 
-               undopar = tmppar2;
-
                while (tmppar != end && tmppar->next()) {
                        tmppar = tmppar->next();
-                       tmppar2->next(new Paragraph(*tmppar, true));
+                       undo_pars.push_back(new Paragraph(*tmppar, true));
+                       size_t const n = undo_pars.size();
+                       undo_pars[n - 2]->next(undo_pars[n - 1]);
+                       undo_pars[n - 1]->previous(undo_pars[n - 2]);
                        // a memory optimization: Just store the layout
                        // information when only edit
                        if (kind == Undo::EDIT) {
-                               tmppar2->clearContents();
+                               undo_pars.back()->clearContents();
                        }
-                       tmppar2->next()->previous(tmppar2);
-
-                       tmppar2 = tmppar2->next();
                }
-               tmppar2->next(0);
+               undo_pars.back()->next(0);
        }
 
        int cursor_par = undoCursor(bv).par()->id();
@@ -372,7 +370,7 @@ bool createUndo(BufferView * bv, Undo::undo_kind kind,
 
        u.reset(new Undo(kind, inset_id,
                before_number, behind_number,
-               cursor_par, cursor_pos, undopar));
+               cursor_par, cursor_pos, undo_pars));
 
        undo_finished = false;
        return true;