Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 3010cd6

Browse files
committed
Saving the last key/index lookup
1 parent 29c97a6 commit 3010cd6

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Angular.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -748,18 +748,26 @@ function arrayRemove(array, value) {
748748
function ES6MapShim() {
749749
this._keys = [];
750750
this._values = [];
751+
this._lastKey = NaN;
752+
this._lastIndex = -1;
751753
}
752754
ES6MapShim.prototype = {
755+
_idx: function(key) {
756+
if (key === this._lastKey) {
757+
return this._lastIndex;
758+
}
759+
return (this._lastIndex = (this._keys.indexOf(this._lastKey = key)));
760+
},
753761
get: function(key) {
754-
var idx = this._keys.indexOf(key);
762+
var idx = this._idx(key);
755763
if (idx !== -1) {
756764
return this._values[idx];
757765
}
758766
},
759767
set: function(key, value) {
760-
var idx = this._keys.indexOf(key);
768+
var idx = this._idx(key);
761769
if (idx === -1) {
762-
idx = this._keys.length;
770+
idx = this._lastIndex = this._keys.length;
763771
}
764772
this._keys[idx] = key;
765773
this._values[idx] = value;

0 commit comments

Comments
 (0)