diff options
author | Austin Ziegler <austin@zieglers.ca> | 2021-12-23 00:18:19 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-23 00:18:19 -0500 |
commit | 04d80e37c225fb071dafd6ddb4d26272d3bda76c (patch) | |
tree | aa365a5ba29dbce43fff690b9e34f33c1f5d1b3f | |
parent | 94c5a412c59cf80c1768ce3d972de48e14dd5248 (diff) | |
parent | 15ec8fa2ceaddeee68a4bdaae0e2252de1c80213 (diff) | |
download | diff-lcs-04d80e37c225fb071dafd6ddb4d26272d3bda76c.tar.gz |
Merge pull request #80 from halostatue/reintroduce-the-threshold-test-optimization
Reintroduce the threshold test optimization
-rw-r--r-- | lib/diff/lcs/internals.rb | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/diff/lcs/internals.rb b/lib/diff/lcs/internals.rb index 74f8909..ef77667 100644 --- a/lib/diff/lcs/internals.rb +++ b/lib/diff/lcs/internals.rb @@ -71,10 +71,15 @@ class << Diff::LCS::Internals bm = b_matches[ai] k = nil bm.reverse_each do |j| - # Previously, we would update `thresh[k] = j` if `k and (thresh[k] > j) and (thresh[k - 1] < j)` - # Otherwise, we would do this. The update appears not to be necessary, so we are trying to - # simplify to: - k = replace_next_larger(thresh, j) + # Although the threshold check is not mandatory for this to work, + # it may have an optimization purpose + # An attempt to remove it: https://github.com/halostatue/diff-lcs/pull/72 + # Why it is reintroduced: https://github.com/halostatue/diff-lcs/issues/78 + if k and (thresh[k] > j) and (thresh[k - 1] < j) + thresh[k] = j + else + k = replace_next_larger(thresh, j, k) + end links[k] = [k.positive? ? links[k - 1] : nil, i, j] unless k.nil? end end |