Skip to content

Commit 2268f1f

Browse files
committed
C++: Speed up "Declaration hides parameter"
Bad magic ended up in `LocalVariable.getFunction` and effectively created a Cartesian product. Before this change, the timing looked like this: Variable::LocalVariable::getFunction_dispred#bb ... 50.1s #select#cpe#123#fff ............................... 20.6s After this change, those predicates become much faster: Variable::LocalVariable::getFunction_dispred#ff ... 121ms DeclarationHidesParameter::localVariableNames#fff . 77ms #select#cpe#123#fff ............................... 28ms Introducing the predicate `localVariableNames` ensures that we can do the main join on two columns simultaneously, so that's a change we should keep even if we remove the `pragma[nomagic]` later.
1 parent 8a435ae commit 2268f1f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

cpp/ql/src/Best Practices/Hiding/DeclarationHidesParameter.ql

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@ ParameterDeclarationEntry functionParameterNames(Function f, string name) {
2828
)
2929
}
3030

31-
from Function f, LocalVariable lv, ParameterDeclarationEntry pde
31+
pragma[nomagic]
32+
LocalVariable localVariableNames(Function f, string name) {
33+
name = result.getName() and
34+
f = result.getFunction()
35+
}
36+
37+
from Function f, LocalVariable lv, ParameterDeclarationEntry pde, string name
3238
where
33-
f = lv.getFunction() and
34-
pde = functionParameterNames(f, lv.getName()) and
39+
lv = localVariableNames(f, name) and
40+
pde = functionParameterNames(f, name) and
3541
not lv.isInMacroExpansion()
3642
select lv, "Local variable '" + lv.getName() + "' hides a $@.", pde, "parameter of the same name"

0 commit comments

Comments
 (0)