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

Commit 105dd5d

Browse files
committed
Saving the last key/index lookup
1 parent d8f593c commit 105dd5d

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/Angular.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -747,18 +747,27 @@ function arrayRemove(array, value) {
747747
function ES6MapShim() {
748748
this._keys = [];
749749
this._values = [];
750+
this._lastKey = NaN;
751+
this._lastIndex = -1;
750752
}
751753
ES6MapShim.prototype = {
754+
_idx: function(key) {
755+
if (key === this._lastKey) {
756+
return this._lastIndex;
757+
}
758+
return (this._lastIndex = (this._keys.indexOf(this._lastKey = key)));
759+
},
752760
get: function(key) {
753-
var idx = this._keys.indexOf(key);
761+
var idx = this._idx(key);
754762
if (idx !== -1) {
755763
return this._values[idx];
756764
}
757765
},
758766
set: function(key, value) {
759-
var idx = this._keys.indexOf(key);
767+
var idx = this._idx(key);
760768
if (idx === -1) {
761-
idx = this._keys.length;
769+
idx = this._lastIndex = this._keys.length;
770+
this._lastKey = key;
762771
}
763772
this._keys[idx] = key;
764773
this._values[idx] = value;

0 commit comments

Comments
 (0)