Browse Source

WebGLShaderCache: Avoid multiple map lookups. (#24457)

* Avoid multiple lookups in WebGLShaderCache _getShaderStage / _getShaderCacheForMaterial

* Update WebGLShaderCache.js

Co-authored-by: Michael Herzog <[email protected]>
John Hurliman 3 years ago
parent
commit
ace307a41f
1 changed files with 9 additions and 6 deletions
  1. 9 6
      src/renderers/webgl/WebGLShaderCache.js

+ 9 - 6
src/renderers/webgl/WebGLShaderCache.js

@@ -77,29 +77,32 @@ class WebGLShaderCache {
 	_getShaderCacheForMaterial( material ) {
 
 		const cache = this.materialCache;
+		let set = cache.get( material );
 
-		if ( cache.has( material ) === false ) {
+		if ( set === undefined ) {
 
-			cache.set( material, new Set() );
+			set = new Set();
+			cache.set( material, set );
 
 		}
 
-		return cache.get( material );
+		return set;
 
 	}
 
 	_getShaderStage( code ) {
 
 		const cache = this.shaderCache;
+		let stage = cache.get( code );
 
-		if ( cache.has( code ) === false ) {
+		if ( stage === undefined ) {
 
-			const stage = new WebGLShaderStage( code );
+			stage = new WebGLShaderStage( code );
 			cache.set( code, stage );
 
 		}
 
-		return cache.get( code );
+		return stage;
 
 	}