From 93fe4412ddfe052f67122a94b195cc66a48e8385 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 11 Jul 2018 16:24:38 +0300 Subject: [PATCH] started building LCS into the diff loop... Signed-off-by: Alex A. Naanou --- diff.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/diff.js b/diff.js index aec4a54..cd0d06d 100644 --- a/diff.js +++ b/diff.js @@ -235,7 +235,6 @@ function(A, B, options){ // ...would need to also include .value (i.e. .valueOf()) and // treat the thing as object... if(A === B || A == B){ - //if(A === B || (options.mode == 'JSON' && A == B)){ return null } @@ -261,9 +260,35 @@ function(A, B, options){ function(a, b){ // XXX cache _diff(..) results... return a === b || a == b || _diff(a, b) }) - // XXX diff only the sections that differ... + // collect gaps between common sections... + common_sections.shift() + var a = 0 + var b = 0 + var gaps = [] + common_sections + // make this consider the tail gap... + .concat({ + A: A.length, + B: B.length, + length: 0, + }) + .forEach(function(e){ + // store the gap... + a != e.A && b != e.B + && gaps.push([ + [a, A.slice(a, e.A)], + [b: B.slice(b, e.B)], + ]) + // go to next gap... + a = e.A + e.length + b = e.B + e.length + }) + + // XXX diff the gaps... // XXX + + // indexed items... _diff_items(res, A, B, options, function(e){ return e == 0 || !!(e*1) })