refactor(collection): use Map instead of Object
This commit is contained in:
parent
1f4caa8773
commit
2a4b63b614
|
@ -45,7 +45,7 @@ export class Injector {
|
|||
|
||||
_createListOfBindings(flattenBindings):List {
|
||||
var bindings = ListWrapper.createFixedSize(Key.numberOfKeys() + 1);
|
||||
MapWrapper.forEach(flattenBindings, (keyId, v) => bindings[keyId] = v);
|
||||
MapWrapper.forEach(flattenBindings, (v, keyId) => bindings[keyId] = v);
|
||||
return bindings;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {MapWrapper} from 'facade/collection';
|
||||
import {MapWrapper, Map} from 'facade/collection';
|
||||
import {FIELD, int, isPresent} from 'facade/lang';
|
||||
|
||||
var _allKeys = {};
|
||||
var _allKeys = MapWrapper.create();
|
||||
var _id:int = 0;
|
||||
|
||||
export class Key {
|
||||
|
@ -15,8 +15,9 @@ export class Key {
|
|||
static get(token) {
|
||||
if (token instanceof Key) return token;
|
||||
|
||||
var obj = MapWrapper.get(_allKeys, token);
|
||||
if (isPresent(obj)) return obj;
|
||||
if (MapWrapper.contains(_allKeys, token)) {
|
||||
return MapWrapper.get(_allKeys, token);
|
||||
}
|
||||
|
||||
var newKey = new Key(token, ++_id);
|
||||
MapWrapper.set(_allKeys, token, newKey);
|
||||
|
|
|
@ -9,7 +9,7 @@ class MapWrapper {
|
|||
static void set(m, k, v){ m[k] = v; }
|
||||
static contains(m, k) => m.containsKey(k);
|
||||
static forEach(m, fn) {
|
||||
m.forEach(fn);
|
||||
m.forEach((k,v) => fn(v,k));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,13 +4,11 @@ export var Set = window.Set;
|
|||
|
||||
export class MapWrapper {
|
||||
static create():Map { return new Map(); }
|
||||
static get(m, k) { return m[k]; }
|
||||
static set(m, k, v) { m[k] = v; }
|
||||
static contains(m, k) { return m[k] != undefined; }
|
||||
static get(m, k) { return m.get(k); }
|
||||
static set(m, k, v) { m.set(k,v); }
|
||||
static contains(m, k) { return m.has(k); }
|
||||
static forEach(m, fn) {
|
||||
for(var k in m) {
|
||||
fn(k, m[k]);
|
||||
}
|
||||
m.forEach(fn);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue