Skip to content

Commit

Permalink
Made DTL_SEPARATE_SIZE and DTL_CONTEXT_SIZE dynamic.
Browse files Browse the repository at this point in the history
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);
  • Loading branch information
wingunder authored and GerHobbelt committed Jun 30, 2024
1 parent 286568f commit 68f77ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
20 changes: 10 additions & 10 deletions dtl/Diff.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -428,7 +428,7 @@ namespace dtl {
case SES_COMMON :
++b;++d;
if (common[1].empty() && adds.empty() && deletes.empty() && change.empty()) {
if (static_cast<long long>(common[0].size()) < DTL_CONTEXT_SIZE) {
if (static_cast<long long>(common[0].size()) < contextSize) {
if (a == 0 && c == 0) {
if (!wasSwapped()) {
a = einfo.beforeIdx;
Expand All @@ -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();
Expand All @@ -467,26 +467,26 @@ namespace dtl {
if (isAfter && !change.empty()) {
sesElemVec_iter cit = it;
long long cnt = 0;
for (long long i=0;i<DTL_SEPARATE_SIZE && (cit != ses_v.end());++i, ++cit) {
for (long long i=0;i<separateSize && (cit != ses_v.end());++i, ++cit) {
if (cit->second.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<long long>(common[0].size()) >= DTL_SEPARATE_SIZE) {
if (static_cast<long long>(common[0].size()) >= separateSize) {
long long c0size = static_cast<long long>(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<c0size - DTL_SEPARATE_SIZE;++i) {
for (long long i=0;i<c0size - separateSize;++i) {
common[0].pop_back();
}
a += c0size - DTL_SEPARATE_SIZE;
c += c0size - DTL_SEPARATE_SIZE;
a += c0size - separateSize;
c += c0size - separateSize;
}
if (a == 0) ++a;
if (c == 0) ++c;
Expand Down
3 changes: 0 additions & 3 deletions dtl/variables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ namespace dtl {
}
} elemInfo;

const long long DTL_SEPARATE_SIZE = 3;
const long long DTL_CONTEXT_SIZE = 3;

/**
* cordinate for registering route
*/
Expand Down

0 comments on commit 68f77ab

Please sign in to comment.