scala-0002: RefChecks.intersectionIsEmpty O(D²) 100x; julia/octave deeper scan CLEAN

This commit is contained in:
russell@unturf.com 2026-03-29 22:11:30 -04:00
parent 2785a0ea1e
commit 4c52d9ee51
4 changed files with 208 additions and 0 deletions

View file

@ -0,0 +1,14 @@
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
index abcdef00..cwe407fix 100644
--- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
@@ -464,7 +464,11 @@ trait RefChecks {
//Console.println(infoString(member) + " overrides " + infoString(other) + " in " + clazz);//DEBUG
/* Is the intersection between given two lists of overridden symbols empty? */
- def intersectionIsEmpty(syms1: List[Symbol], syms2: List[Symbol]) = !syms1.exists(syms2.contains)
+ // CWE-407 fix: syms2.contains on List[Symbol] is O(|syms2|) per call.
+ // extendedOverriddenSymbols returns O(D) symbols (D = hierarchy depth).
+ // Original: O(|syms1| x |syms2|) = O(D^2) per pair checked in checkAllOverrides.
+ // Fix: convert syms2 to a Set[Symbol] once — O(|syms2|) — then O(1) per lookup.
+ def intersectionIsEmpty(syms1: List[Symbol], syms2: List[Symbol]) = { val s2 = syms2.toSet; !syms1.exists(s2.contains) }