diff options
author | tiendo1011 <tiendo1011@gmail.com> | 2021-12-22 14:22:06 +0700 |
---|---|---|
committer | tiendo1011 <tiendo1011@gmail.com> | 2021-12-22 14:22:06 +0700 |
commit | 15ec8fa2ceaddeee68a4bdaae0e2252de1c80213 (patch) | |
tree | 0f3b803e85edf36f96ddd23bfefb0ba06b8ab204 /lib | |
parent | c2a5b875a81c5882ed3de16b7aeaae2ac989e3e6 (diff) | |
download | diff-lcs-15ec8fa2ceaddeee68a4bdaae0e2252de1c80213.tar.gz |
Reintroduce the threshold test optimizationreintroduce-the-threshold-test-optimization
Diffstat (limited to 'lib')
-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 |