Skip to content

Commit 3e02bfd

Browse files
committed
Remove unnecessary keys bookkeeping.
1 parent 82958d4 commit 3e02bfd

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

src/lib/template/dom-repeat.html

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,9 @@
330330
this._splices = [];
331331
// Update final _keyToInstIdx and instance indices
332332
var keyToIdx = this._keyToInstIdx = {};
333-
var keys = this._keys;
334-
for (var i=0; i<keys.length; i++) {
335-
var key = keys[i];
336-
keyToIdx[key] = i;
333+
for (var i=0; i<this._instances.length; i++) {
337334
var inst = this._instances[i];
335+
keyToIdx[inst.__key__] = i;
338336
inst.__setProperty(this.indexAs, i, true);
339337
}
340338
this.fire('dom-change');
@@ -348,31 +346,31 @@
348346
var c = this.collection;
349347
// Start with unordered keys for user sort,
350348
// or get them in array order for array order
349+
var keys;
351350
if (this._sortFn) {
352-
this._keys = c ? c.getKeys() : [];
351+
keys = c ? c.getKeys() : [];
353352
} else {
354-
this._keys = [];
353+
keys = [];
355354
var items = this.items;
356355
if (items) {
357356
for (var i=0; i<items.length; i++) {
358-
this._keys.push(c.getKey(items[i]));
357+
keys.push(c.getKey(items[i]));
359358
}
360359
}
361360
}
362361
// Apply user filter to keys
363362
if (this._filterFn) {
364-
this._keys = this._keys.filter(function(a) {
363+
keys = keys.filter(function(a) {
365364
return this._filterFn(c.getItem(a));
366365
}, this);
367366
}
368367
// Apply user sort to keys
369368
if (this._sortFn) {
370-
this._keys.sort(function(a, b) {
369+
keys.sort(function(a, b) {
371370
return this._sortFn(c.getItem(a), c.getItem(b));
372371
}.bind(this));
373372
}
374373
// Generate instances and assign items and keys
375-
var keys = this._keys;
376374
for (var i=0; i<keys.length; i++) {
377375
var key = keys[i];
378376
var inst = this._instances[i];
@@ -400,7 +398,6 @@
400398
// first, and added rows are insertion-sorted into place using user sort
401399
_applySplicesUserSort: function(splices) {
402400
var c = this.collection;
403-
var keys = this._keys;
404401
var instances = this._instances;
405402
var keyMap = {};
406403
var pool = [];
@@ -438,7 +435,6 @@
438435
if (idx !== undefined) {
439436
pool.push(this._detachRow(idx));
440437
instances.splice(idx, 1);
441-
keys.splice(idx, 1);
442438
}
443439
}
444440
}
@@ -471,7 +467,7 @@
471467
// Binary search for insertion point
472468
while (start <= end) {
473469
var mid = (start + end) >> 1;
474-
var midKey = this._keys[mid];
470+
var midKey = this._instances[mid].__key__;
475471
var cmp = sortFn(c.getItem(midKey), item);
476472
if (cmp < 0) {
477473
start = mid + 1;
@@ -485,26 +481,20 @@
485481
if (idx < 0) {
486482
idx = end + 1;
487483
}
488-
// Insert key & inst at insertion point
489-
this._keys.splice(idx, 0, key);
484+
// Insert instance at insertion point
490485
this._instances.splice(idx, 0, this._insertRow(idx, key, pool));
491486
return idx;
492487
},
493488

494-
// Render method 3: incremental update using splices with array sort
489+
// Render method 3: incremental update using splices with array order
495490
// ----
496491
// Splices are processed in order; removed rows are pooled, and added
497-
// rows are inserted based on splice index; placeholders are used when
498-
// inserting rows when pool is empty, and placeholders are updated to
492+
// rows are as placeholders, and placeholders are updated to
499493
// actual rows at the end to take full advantage of removed rows
500494
_applySplicesArrayOrder: function(splices) {
501-
var keys = this._keys;
502495
var pool = [];
503496
var c = this.collection;
504497
splices.forEach(function(s) {
505-
// Apply splices to keys
506-
var args = [s.index, s.removed.length].concat(s.added);
507-
keys.splice.apply(keys, args);
508498
// Detach & pool removed instances
509499
for (var i=0; i<s.removed.length; i++) {
510500
var inst = this._detachRow(s.index + i);

0 commit comments

Comments
 (0)