diff options
author | tiendo1011 <tiendo1011@gmail.com> | 2021-12-22 13:46:42 +0700 |
---|---|---|
committer | tiendo1011 <tiendo1011@gmail.com> | 2021-12-22 13:46:42 +0700 |
commit | 47ad358795caf269a47a054d249d017f5eb72ce4 (patch) | |
tree | 84cd1e6a122b2d6608db3204bc2cdee729eec98c | |
parent | fbedcd9d1afa7af9a1df55c158dd9baa731e6b20 (diff) | |
download | diff-lcs-47ad358795caf269a47a054d249d017f5eb72ce4.tar.gz |
Apply some performance improvement
-rw-r--r-- | lib/diff/lcs.rb | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/diff/lcs.rb b/lib/diff/lcs.rb index f3716e1..8425d15 100644 --- a/lib/diff/lcs.rb +++ b/lib/diff/lcs.rb @@ -293,16 +293,18 @@ class << Diff::LCS ai = bj = 0 matches.each do |b_line| - ax = string ? seq1[ai, 1] : seq1[ai] - bx = string ? seq2[bj, 1] : seq2[bj] - if b_line.nil? - unless ax.nil? or (string and ax.empty?) + unless seq1[ai].nil? + ax = string ? seq1[ai, 1] : seq1[ai] + bx = string ? seq2[bj, 1] : seq2[bj] + event = Diff::LCS::ContextChange.new('-', ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_a(event) end else + ax = string ? seq1[ai, 1] : seq1[ai] + loop do break unless bj < b_line |