浏览代码

Eliminate redundant object creation

Instead of creating a new GC'ed object for each object we traverse,
pre-create the _box similarly to other globals. This is slightly awkward
since this needs to be done after we define the ctor.
Arseny Kapoulkine 5 年之前
父节点
当前提交
43cd006f03
共有 1 个文件被更改,包括 6 次插入6 次删除
  1. 6 6
      src/math/Box3.js

+ 6 - 6
src/math/Box3.js

@@ -41,6 +41,8 @@ function Box3( min, max ) {
 
 }
 
+var _box = new Box3();
+
 Object.assign( Box3.prototype, {
 
 	isBox3: true,
@@ -257,13 +259,11 @@ Object.assign( Box3.prototype, {
 
 			}
 
-			var box = new Box3();
-
-			box.copy( geometry.boundingBox );
-			box.applyMatrix4( object.matrixWorld );
+			_box.copy( geometry.boundingBox );
+			_box.applyMatrix4( object.matrixWorld );
 
-			this.expandByPoint( box.min );
-			this.expandByPoint( box.max );
+			this.expandByPoint( _box.min );
+			this.expandByPoint( _box.max );
 
 		}