Skip to content

Commit ee6265c

Browse files
committed
reduce dictionary lookups
1 parent b9ee8e6 commit ee6265c

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/graphics/shader-node-registry.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,31 @@ ShaderNodeRegistry.prototype._genVariantKey = function (argTypes, options) {
5757
};
5858

5959
ShaderNodeRegistry.prototype.get = function (name, argTypes, options) {
60-
if (this._nodeCache[name]) {
61-
if (!this._nodeDef[name].gen) {
60+
var cachedNode = this._nodeCache[name];
61+
if (cachedNode) {
62+
var nodeDef = this._nodeDef[name];
63+
if (!nodeDef.gen) {
6264
// if no generator, passthrough
63-
if (!this._nodeCache[name].def) {
64-
this._nodeCache[name].def = new ShaderGraphNode(this._nodeDef[name].code);
65+
if (!cachedNode.def) {
66+
cachedNode.def = new ShaderGraphNode(nodeDef.code);
6567
}
66-
return this._nodeCache[name].def;
68+
return cachedNode.def;
6769
}
6870

6971
var variantKey = this._genVariantKey(argTypes, options);
70-
if (this._nodeCache[name][variantKey]) {
72+
if (cachedNode[variantKey]) {
7173
// return cached variant
72-
return this._nodeCache[name][variantKey];
74+
return cachedNode[variantKey];
7375
}
7476

7577
// generate variant, add to cache and return it
76-
var variantCode = this._nodeDef[name].gen(argTypes, options);
78+
var variantCode = nodeDef.gen(argTypes, options);
7779
if (variantCode) {
78-
this._nodeCache[name][variantKey] = new ShaderGraphNode(variantCode);
80+
cachedNode[variantKey] = new ShaderGraphNode(variantCode);
7981

80-
this._nodeCache[name][variantKey]._precision = ((options && options.precision) ? options.precision : '');
82+
cachedNode[variantKey]._precision = ((options && options.precision) ? options.precision : '');
8183

82-
return this._nodeCache[name][variantKey];
84+
return cachedNode[variantKey];
8385
}
8486
}
8587
};

0 commit comments

Comments
 (0)