MCPcopy Create free account
hub / github.com/WebReflection/hypersimple / applyDiff

Function applyDiff

index.js:368–407  ·  view source on GitHub ↗
(diff, get, parentNode, futureNodes, futureStart, currentNodes, currentStart, currentLength, before)

Source from the content-addressed store, hash-verified

366 };
367
368 var applyDiff = function applyDiff(diff, get, parentNode, futureNodes, futureStart, currentNodes, currentStart, currentLength, before) {
369 var live = [];
370 var length = diff.length;
371 var currentIndex = currentStart;
372 var i = 0;
373
374 while (i < length) {
375 switch (diff[i++]) {
376 case SKIP:
377 futureStart++;
378 currentIndex++;
379 break;
380
381 case INSERTION:
382 // TODO: bulk appends for sequential nodes
383 live.push(futureNodes[futureStart]);
384 append(get, parentNode, futureNodes, futureStart++, futureStart, currentIndex < currentLength ? get(currentNodes[currentIndex], 0) : before);
385 break;
386
387 case DELETION:
388 currentIndex++;
389 break;
390 }
391 }
392
393 i = 0;
394
395 while (i < length) {
396 switch (diff[i++]) {
397 case SKIP:
398 currentStart++;
399 break;
400
401 case DELETION:
402 // TODO: bulk removes for sequential nodes
403 if (-1 < live.indexOf(currentNodes[currentStart])) currentStart++;else remove(get, currentNodes, currentStart++, currentStart);
404 break;
405 }
406 }
407 };
408
409 var findK = function findK(ktr, length, j) {
410 var lo = 1;

Callers 1

smartDiffFunction · 0.85

Calls 3

appendFunction · 0.85
getFunction · 0.85
removeFunction · 0.85

Tested by

no test coverage detected