From 1a27aaca77588458343373c8fc7ecd01a22d2e73 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sun, 9 Aug 2009 19:51:12 +0000 Subject: [PATCH] RandomAccessList: new swap() method for swapping two elements without any copy. LFUN_PARAGRAPH_MOVE_UP and LFUN_PARAGRAPH_MOVE_DOWN: use that. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30958 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Text3.cpp | 4 ++-- src/support/RandomAccessList.h | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Text3.cpp b/src/Text3.cpp index a84c4a05e8..86d1ba6a11 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -554,7 +554,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) pit_type const pit = cur.pit(); recUndo(cur, pit, pit + 1); cur.finishUndo(); - swap(pars_[pit], pars_[pit + 1]); + pars_.swap(pit, pit + 1); cur.buffer()->updateLabels(); needsUpdate = true; ++cur.pit(); @@ -565,7 +565,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) pit_type const pit = cur.pit(); recUndo(cur, pit - 1, pit); cur.finishUndo(); - swap(pars_[pit], pars_[pit - 1]); + pars_.swap(pit, pit - 1); cur.buffer()->updateLabels(); --cur.pit(); needsUpdate = true; diff --git a/src/support/RandomAccessList.h b/src/support/RandomAccessList.h index fa37be9fd3..5014378c44 100644 --- a/src/support/RandomAccessList.h +++ b/src/support/RandomAccessList.h @@ -246,6 +246,15 @@ public: return it; } + void swap(size_t i, size_t j) + { + size_t const p = max(i, j); + size_t const q = min(i, j); + container_.splice(iterCont_[p], container_, iterCont_[q]); + container_.splice(iterCont_[q], container_, iterCont_[p]); + recreateVector(); + } + void swap(RandomAccessList & x) { std::swap(container_, x.container_); -- 2.39.5