mirror of
https://github.com/github/codeql.git
synced 2026-05-01 19:55:15 +02:00
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.
This commit is contained in:
@@ -28,9 +28,15 @@ ParameterDeclarationEntry functionParameterNames(Function f, string name) {
|
||||
)
|
||||
}
|
||||
|
||||
from Function f, LocalVariable lv, ParameterDeclarationEntry pde
|
||||
pragma[nomagic]
|
||||
LocalVariable localVariableNames(Function f, string name) {
|
||||
name = result.getName() and
|
||||
f = result.getFunction()
|
||||
}
|
||||
|
||||
from Function f, LocalVariable lv, ParameterDeclarationEntry pde, string name
|
||||
where
|
||||
f = lv.getFunction() and
|
||||
pde = functionParameterNames(f, lv.getName()) and
|
||||
lv = localVariableNames(f, name) and
|
||||
pde = functionParameterNames(f, name) and
|
||||
not lv.isInMacroExpansion()
|
||||
select lv, "Local variable '" + lv.getName() + "' hides a $@.", pde, "parameter of the same name"
|
||||
|
||||
Reference in New Issue
Block a user