short-circuit keys algorithm if no keys changed

This commit is contained in:
Leo Horie 2014-11-28 12:44:43 -05:00
parent b6693c7f06
commit c9c0250f12

View file

@ -127,14 +127,24 @@ var m = (function app(window, undefined) {
var DELETION = 1, INSERTION = 2 , MOVE = 3;
var existing = {}, unkeyed = [], shouldMaintainIdentities = false;
for (var i = 0; i < cached.length; i++) {
if (cached[i] && cached[i].attrs && cached[i].attrs.key != null) {
if (cached[i].attrs && cached[i].attrs.key != null) {
shouldMaintainIdentities = true;
existing[cached[i].attrs.key] = {action: DELETION, index: i}
}
}
if (shouldMaintainIdentities) {
var keysDiffer = false
if (data.length != cached.length) keysDiffer = true
else for (var i = 0; i < data.length; i++) {
if (cached[i].attrs && data[i].attrs && cached[i].attrs.key != data[i].attrs.key) {
keysDiffer = true
break
}
}
if (keysDiffer) {
for (var i = 0; i < data.length; i++) {
if (data[i] && data[i].attrs) {
if (data[i].attrs) {
if (data[i].attrs.key != null) {
var key = data[i].attrs.key;
if (!existing[key]) existing[key] = {action: INSERTION, index: i};
@ -181,6 +191,7 @@ var m = (function app(window, undefined) {
cached.nodes = new Array(parentElement.childNodes.length);
for (var i = 0, child; child = parentElement.childNodes[i]; i++) cached.nodes[i] = child
}
}
//end key algorithm
for (var i = 0, cacheCount = 0; i < data.length; i++) {