From b1494325124c8f4ecbf810ce6e196b3a1fa70b02 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 31 Oct 2015 05:15:47 +0100 Subject: [PATCH] fix/change DiffApplicator to allow applying several diffs basically we need a reset-Hook before applying the next diff, because the existing elements need to be swaped and the position reset to start --- src/lib/diff/diff-language.hpp | 1 + src/lib/diff/list-diff-application.hpp | 10 +++++++--- src/lib/diff/tree-diff-application.hpp | 12 +++++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/lib/diff/diff-language.hpp b/src/lib/diff/diff-language.hpp index 0b3b90d38..207d29fa3 100644 --- a/src/lib/diff/diff-language.hpp +++ b/src/lib/diff/diff-language.hpp @@ -294,6 +294,7 @@ namespace diff{ void consume (DIFF&& diff) { + target_.initDiffApplication(); for ( ; diff; ++diff ) diff->applyTo(target_); } diff --git a/src/lib/diff/list-diff-application.hpp b/src/lib/diff/list-diff-application.hpp index 54cb41390..f2bb2c614 100644 --- a/src/lib/diff/list-diff-application.hpp +++ b/src/lib/diff/list-diff-application.hpp @@ -162,10 +162,14 @@ namespace diff{ explicit DiffApplicationStrategy(vector& targetVector) : seq_(targetVector) - , pos_(seq_.begin()) + { } + + void + initDiffApplication() { - swap (seq_, orig_); // pos_ still refers to original input sequence, which has been moved to orig_ - seq_.reserve (targetVector.size() * 120 / 100); // heuristics for storage pre-allocation + swap (seq_, orig_); + seq_.reserve (orig_.size() * 120 / 100); // heuristics for storage pre-allocation + pos_ = orig_.begin(); } }; diff --git a/src/lib/diff/tree-diff-application.hpp b/src/lib/diff/tree-diff-application.hpp index 52a6b73e0..cf2791e60 100644 --- a/src/lib/diff/tree-diff-application.hpp +++ b/src/lib/diff/tree-diff-application.hpp @@ -102,6 +102,9 @@ namespace diff{ ScopeFrame(Mutator& toModify) : target(toModify) , content() + { } + + void init() { target.swapContent (content); } @@ -298,7 +301,7 @@ namespace diff{ __expect_successful_location(n); - if (srcPos()->matches(n)) + if (not endOfData() and srcPos()->matches(n)) ++src(); // get /after/ an explicitly given position } @@ -328,6 +331,13 @@ namespace diff{ { scopes_.emplace(mutableTargetRecord); } + + void + initDiffApplication() + { + REQUIRE (1 == scopes_.size()); + scopes_.top().init(); + } };