10000 Replace arrays and `HashMap` with native `Map` (with a fallback shim implementation) by gkalpak · Pull Request #15114 · angular/angular.js · GitHub
[go: up one dir, main page]

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

Replace arrays and HashMap with native Map (with a fallback shim implementation) #15114

Closed
wants to merge 9 commits into from
Prev Previous commit
Next Next commit
fixup! perf(copy): Saving the last key/index lookup in ESMapShim
  • Loading branch information
jbedard authored and gkalpak committed Sep 9, 2016
commit 8f4eab4d0e3ff877008ad55a8622fd1d308885af
15 changes: 12 additions & 3 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -753,18 +753,27 @@ function arrayRemove(array, value) {
function ES6MapShim() {
this._keys = [];
this._values = [];
this._lastKey = NaN;
this._lastIndex = -1;
}
ES6MapShim.prototype = {
_idx: function(key) {
if (key === this._lastKey) {
return this._lastIndex;
}
return (this._lastIndex = (this._keys.indexOf(this._lastKey = key)));
},
get: function(key) {
var idx = this._keys.indexOf(key);
var idx = this._idx(key);
if (idx !== -1) {
return this._values[idx];
}
},
set: function(key, value) {
var idx = this._keys.indexOf(key);
var idx = this._idx(key);
if (idx === -1) {
idx = this._keys.length;
idx = this._lastIndex = this._keys.length;
this._lastKey = key;
}
this._keys[idx] = key;
this._values[idx] = value;
Expand Down
0