From 28e91c464e72c03618e38df1a6b0089c43af3d2c Mon Sep 17 00:00:00 2001 From: Alexander Rose Date: Thu, 3 Sep 2015 01:11:27 +0200 Subject: [PATCH] Faster checkEdge function This one uses a double hash, though the second hash is just a list that is linearly scanned as it is expected to be very small (there are not many edges per vertex). --- src/renderers/webgl/WebGLObjects.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/renderers/webgl/WebGLObjects.js b/src/renderers/webgl/WebGLObjects.js index 7883ecede6..f86e10e2aa 100644 --- a/src/renderers/webgl/WebGLObjects.js +++ b/src/renderers/webgl/WebGLObjects.js @@ -191,13 +191,29 @@ THREE.WebGLObjects = function ( gl, properties, info ) { function checkEdge( edges, a, b ) { - var hash = a < b ? a + '_' + b : b + '_' + a; + if ( a > b ){ - if ( edges.hasOwnProperty( hash ) ) return false; + var tmp = a; + a = b; + b = tmp; - edges[ hash ] = 1; + } + + var list = edges[ a ]; + + if( list === undefined ){ + + edges[ a ] = [ b ]; + return true; + + }else if( list.indexOf( b ) === -1 ){ + + list.push( b ); + return true; + + } - return true; + return false; } -- GitLab