From 68f77ab60d2107bb634ba5a0d3f684cf7785b4e3 Mon Sep 17 00:00:00 2001 From: Pieter du Preez Date: Fri, 11 Oct 2019 20:21:00 +0000 Subject: [PATCH] Made DTL_SEPARATE_SIZE and DTL_CONTEXT_SIZE dynamic. This patch replaces the DTL_SEPARATE_SIZE and DTL_CONTEXT_SIZE constants. The API however stays backwards compatible. The user now has the option to set the separateSize amd contextSize, when calling composeUnifiedHunks(). eg. diff.composeUnifiedHunks(20, 5); --- dtl/Diff.hpp | 20 ++++++++++---------- dtl/variables.hpp | 3 --- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/dtl/Diff.hpp b/dtl/Diff.hpp index 6d4fff7..91978fa 100644 --- a/dtl/Diff.hpp +++ b/dtl/Diff.hpp @@ -380,7 +380,7 @@ namespace dtl { /** * compose Unified Format Hunks from Shortest Edit Script */ - void composeUnifiedHunks () { + void composeUnifiedHunks (const long long separateSize = 3, const long long contextSize = 3) { sesElemVec common[2]; sesElemVec change; sesElemVec ses_v = ses.getSequence(); @@ -428,7 +428,7 @@ namespace dtl { case SES_COMMON : ++b;++d; if (common[1].empty() && adds.empty() && deletes.empty() && change.empty()) { - if (static_cast(common[0].size()) < DTL_CONTEXT_SIZE) { + if (static_cast(common[0].size()) < contextSize) { if (a == 0 && c == 0) { if (!wasSwapped()) { a = einfo.beforeIdx; @@ -452,7 +452,7 @@ namespace dtl { joinSesVec(change, deletes); joinSesVec(change, adds); change.push_back(*it); - if (middle >= DTL_SEPARATE_SIZE || l_cnt >= length) { + if (middle >= separateSize || l_cnt >= length) { isAfter = true; } adds.clear(); @@ -467,26 +467,26 @@ namespace dtl { if (isAfter && !change.empty()) { sesElemVec_iter cit = it; long long cnt = 0; - for (long long i=0;isecond.type == SES_COMMON) { ++cnt; } } - if (cnt < DTL_SEPARATE_SIZE && l_cnt < length) { + if (cnt < separateSize && l_cnt < length) { middle = 0; isAfter = false; continue; } - if (static_cast(common[0].size()) >= DTL_SEPARATE_SIZE) { + if (static_cast(common[0].size()) >= separateSize) { long long c0size = static_cast(common[0].size()); rotate(common[0].begin(), - common[0].begin() + (size_t)c0size - DTL_SEPARATE_SIZE, + common[0].begin() + (size_t)c0size - separateSize, common[0].end()); - for (long long i=0;i