From: André Pönitz Date: Fri, 2 May 2003 13:11:39 +0000 (+0000) Subject: * undo_funcs.C: X-Git-Tag: 1.6.10~16863 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=4b8025d992a42732a0f0d4ca49fb04129dd9046d;p=features.git * undo_funcs.C: * undo.[Ch]: rely on std::vector instead of manually linked lists git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6923 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/ChangeLog b/src/ChangeLog index fec14f53be..c5e30142ee 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,7 +1,11 @@ 2003-05-02 André Pönitz - * 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 instead of manually + linked lists 2003-05-02 Lars Gullik Bjønnes diff --git a/src/undo.C b/src/undo.C index 1d30403882..9b093e41ed 100644 --- a/src/undo.C +++ b/src/undo.C @@ -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 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::iterator it = pars.begin(); + std::vector::iterator end = pars.end(); + for ( ; it != end; ++it) + delete *it; } diff --git a/src/undo.h b/src/undo.h index 4abd779396..19fb2d1363 100644 --- a/src/undo.h +++ b/src/undo.h @@ -12,6 +12,8 @@ #ifndef UNDO_H #define UNDO_H +#include + class Paragraph; /// @@ -41,12 +43,12 @@ public: /// int cursor_pos; // valid if >= 0 /// - Paragraph * par; + std::vector 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 const & par_arg); /// ~Undo(); }; diff --git a/src/undo_funcs.C b/src/undo_funcs.C index 0765fb501d..c484bc5fdc 100644 --- a/src/undo_funcs.C +++ b/src/undo_funcs.C @@ -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 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;