SFML 5 defects: VideoMode dedup x3 (139x), allWindows erase (1001x), GL ext (149x) AngelScript 3 defects: FindNewOwner (100x), CompileSwitch (250x) Three.js 5 defects: WebGL binding (22x), StackNode filter (1875x), NodeBuilder (517x) pygame 4 defects: remove_internal (3001x), spritecollide dokill (3001x), switch_layer (3001x) Whitepaper: 98→115 sites, 44→48 ecosystems All unit tests pass: 6/6 each
26 lines
1.3 KiB
Diff
26 lines
1.3 KiB
Diff
Fixes threejs-0001: WebGLUniformsGroups.allocateBindingPointIndex() uses Array.indexOf()
|
|
inside a for loop — O(n²) binding point allocation, fires per material per frame.
|
|
|
|
--- a/src/renderers/webgl/WebGLUniformsGroups.js
|
|
+++ b/src/renderers/webgl/WebGLUniformsGroups.js
|
|
@@ -... (module scope, near allocatedBindingPoints declaration)
|
|
- const allocatedBindingPoints = [];
|
|
+ const allocatedBindingPoints = []; // preserved for compatibility (indexOf used at line 377)
|
|
+ const allocatedBindingPointsSet = new Set(); // FIX threejs-0001: O(1) membership — CWE-407
|
|
|
|
function allocateBindingPointIndex() {
|
|
for ( let i = 0; i < maxBindingPoints; i ++ ) {
|
|
- if ( allocatedBindingPoints.indexOf( i ) === - 1 ) { // O(n) per iteration — CWE-407
|
|
+ if ( ! allocatedBindingPointsSet.has( i ) ) { // O(1) — fixed
|
|
allocatedBindingPoints.push( i );
|
|
+ allocatedBindingPointsSet.add( i );
|
|
return i;
|
|
}
|
|
}
|
|
}
|
|
|
|
# Also maintain set in the release path (wherever allocatedBindingPoints.splice() is called):
|
|
+ allocatedBindingPointsSet.delete( index );
|
|
|
|
# Simpler alternative: replace allocatedBindingPoints array entirely with a Set,
|
|
# change indexOf usage at line 377 to has(). No backward compat concern — internal only.
|