summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortiendo1011 <tiendo1011@gmail.com>2021-12-22 14:22:06 +0700
committertiendo1011 <tiendo1011@gmail.com>2021-12-22 14:22:06 +0700
commit15ec8fa2ceaddeee68a4bdaae0e2252de1c80213 (patch)
tree0f3b803e85edf36f96ddd23bfefb0ba06b8ab204
parentc2a5b875a81c5882ed3de16b7aeaae2ac989e3e6 (diff)
downloaddiff-lcs-15ec8fa2ceaddeee68a4bdaae0e2252de1c80213.tar.gz
Reintroduce the threshold test optimizationreintroduce-the-threshold-test-optimization
-rw-r--r--lib/diff/lcs/internals.rb13
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