diff --git a/cjs/index.js b/cjs/index.js index 4566c30..818cb6e 100644 --- a/cjs/index.js +++ b/cjs/index.js @@ -38,7 +38,7 @@ module.exports = (parentNode, a, b, get, before) => { if (aEnd === aStart) { // we could be in a situation where the rest of nodes that // need to be added are not at the end, and in such case - // the node to `insertBefore`, if the index is more than 0 + // the node to `moveBefore`, if the index is more than 0 // must be retrieved, otherwise it's gonna be the first item. const node = bEnd < bLength ? (bStart ? @@ -46,7 +46,7 @@ module.exports = (parentNode, a, b, get, before) => { get(b[bEnd - bStart], 0)) : before; while (bStart < bEnd) - parentNode.insertBefore(get(b[bStart++], 1), node); + parentNode.moveBefore(get(b[bStart++], 1), node); } // remove head or tail: fast path else if (bEnd === bStart) { @@ -81,11 +81,11 @@ module.exports = (parentNode, a, b, get, before) => { // [1, 2, 3, 4, 5] // [1, 2, 3, 5, 6, 4] const node = get(a[--aEnd], -1).nextSibling; - parentNode.insertBefore( + parentNode.moveBefore( get(b[bStart++], 1), get(a[aStart++], -1).nextSibling ); - parentNode.insertBefore(get(b[--bEnd], 1), node); + parentNode.moveBefore(get(b[--bEnd], 1), node); // mark the future index as identical (yeah, it's dirty, but cheap 👍) // The main reason to do this, is that when a[aEnd] will be reached, // the loop will likely be on the fast path, as identical to b[bEnd]. @@ -131,7 +131,7 @@ module.exports = (parentNode, a, b, get, before) => { if (sequence > (index - bStart)) { const node = get(a[aStart], 0); while (bStart < index) - parentNode.insertBefore(get(b[bStart++], 1), node); + parentNode.moveBefore(get(b[bStart++], 1), node); } // if the effort wasn't good enough, fallback to a replace, // moving both source and target indexes forward, hoping that some diff --git a/esm/index.js b/esm/index.js index fdc7508..08ff862 100644 --- a/esm/index.js +++ b/esm/index.js @@ -37,7 +37,7 @@ export default (parentNode, a, b, get, before) => { if (aEnd === aStart) { // we could be in a situation where the rest of nodes that // need to be added are not at the end, and in such case - // the node to `insertBefore`, if the index is more than 0 + // the node to `moveBefore`, if the index is more than 0 // must be retrieved, otherwise it's gonna be the first item. const node = bEnd < bLength ? (bStart ? @@ -45,7 +45,7 @@ export default (parentNode, a, b, get, before) => { get(b[bEnd - bStart], 0)) : before; while (bStart < bEnd) - parentNode.insertBefore(get(b[bStart++], 1), node); + parentNode.moveBefore(get(b[bStart++], 1), node); } // remove head or tail: fast path else if (bEnd === bStart) { @@ -80,11 +80,11 @@ export default (parentNode, a, b, get, before) => { // [1, 2, 3, 4, 5] // [1, 2, 3, 5, 6, 4] const node = get(a[--aEnd], -1).nextSibling; - parentNode.insertBefore( + parentNode.moveBefore( get(b[bStart++], 1), get(a[aStart++], -1).nextSibling ); - parentNode.insertBefore(get(b[--bEnd], 1), node); + parentNode.moveBefore(get(b[--bEnd], 1), node); // mark the future index as identical (yeah, it's dirty, but cheap 👍) // The main reason to do this, is that when a[aEnd] will be reached, // the loop will likely be on the fast path, as identical to b[bEnd]. @@ -130,7 +130,7 @@ export default (parentNode, a, b, get, before) => { if (sequence > (index - bStart)) { const node = get(a[aStart], 0); while (bStart < index) - parentNode.insertBefore(get(b[bStart++], 1), node); + parentNode.moveBefore(get(b[bStart++], 1), node); } // if the effort wasn't good enough, fallback to a replace, // moving both source and target indexes forward, hoping that some diff --git a/index.js b/index.js index 2c0e9b7..c820f84 100644 --- a/index.js +++ b/index.js @@ -40,10 +40,10 @@ var udomdiff = (function (exports) { if (aEnd === aStart) { // we could be in a situation where the rest of nodes that // need to be added are not at the end, and in such case - // the node to `insertBefore`, if the index is more than 0 + // the node to `moveBefore`, if the index is more than 0 // must be retrieved, otherwise it's gonna be the first item. var node = bEnd < bLength ? bStart ? get(b[bStart - 1], -0).nextSibling : get(b[bEnd - bStart], 0) : before; - while (bStart < bEnd) parentNode.insertBefore(get(b[bStart++], 1), node); + while (bStart < bEnd) parentNode.moveBefore(get(b[bStart++], 1), node); } // remove head or tail: fast path else if (bEnd === bStart) { @@ -74,8 +74,8 @@ var udomdiff = (function (exports) { // [1, 2, 3, 4, 5] // [1, 2, 3, 5, 6, 4] var _node = get(a[--aEnd], -1).nextSibling; - parentNode.insertBefore(get(b[bStart++], 1), get(a[aStart++], -1).nextSibling); - parentNode.insertBefore(get(b[--bEnd], 1), _node); + parentNode.moveBefore(get(b[bStart++], 1), get(a[aStart++], -1).nextSibling); + parentNode.moveBefore(get(b[--bEnd], 1), _node); // mark the future index as identical (yeah, it's dirty, but cheap 👍) // The main reason to do this, is that when a[aEnd] will be reached, // the loop will likely be on the fast path, as identical to b[bEnd]. @@ -118,7 +118,7 @@ var udomdiff = (function (exports) { // will be processed at zero cost if (sequence > index - bStart) { var _node2 = get(a[aStart], 0); - while (bStart < index) parentNode.insertBefore(get(b[bStart++], 1), _node2); + while (bStart < index) parentNode.moveBefore(get(b[bStart++], 1), _node2); } // if the effort wasn't good enough, fallback to a replace, // moving both source and target indexes forward, hoping that some diff --git a/min.js b/min.js index 6bd938b..eb68f50 100644 --- a/min.js +++ b/min.js @@ -1 +1 @@ -var udomdiff=(e=>(e.default=function(e,r,i,f,l){for(var n=i.length,t=r.length,o=n,s=0,a=0,v=null;s(e.default=function(e,r,f,l,i){for(var o=f.length,v=r.length,a=o,n=0,t=0,s=null;n{const f=i.length;let n=t.length,s=f,o=0,c=0,u=null;for(;or-c){const f=l(t[o],0);for(;c{const i=o.length;let r=l.length,n=i,s=0,c=0,u=null;for(;st-c){const i=f(l[s],0);for(;c