Skip to content

Commit 3a3aa75

Browse files
authored
Merge pull request github#2935 from jbj/MissingEnumCaseInSwitch-perf
C++: Optimize EnumSwitch.getAMissingCase
2 parents b210009 + 30b5db3 commit 3a3aa75

File tree

1 file changed

+7
-19
lines changed
  • cpp/ql/src/semmle/code/cpp/stmts

1 file changed

+7
-19
lines changed

cpp/ql/src/semmle/code/cpp/stmts/Stmt.qll

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,30 +1604,18 @@ class EnumSwitch extends SwitchStmt {
16041604
* ```
16051605
* there are results `GREEN` and `BLUE`.
16061606
*/
1607-
pragma[noopt]
16081607
EnumConstant getAMissingCase() {
16091608
exists(Enum et |
1610-
exists(Expr e, Type t |
1611-
e = this.getExpr() and
1612-
this instanceof EnumSwitch and
1613-
t = e.getType() and
1614-
et = t.getUnderlyingType()
1615-
) and
1609+
et = this.getExpr().getUnderlyingType() and
16161610
result = et.getAnEnumConstant() and
1617-
not exists(string value |
1618-
exists(SwitchCase sc, Expr e |
1619-
sc = this.getASwitchCase() and
1620-
e = sc.getExpr() and
1621-
value = e.getValue()
1622-
) and
1623-
exists(Initializer init, Expr e |
1624-
init = result.getInitializer() and
1625-
e = init.getExpr() and
1626-
e.getValue() = value
1627-
)
1628-
)
1611+
not this.matchesValue(result.getInitializer().getExpr().getValue())
16291612
)
16301613
}
1614+
1615+
pragma[noinline]
1616+
private predicate matchesValue(string value) {
1617+
value = this.getASwitchCase().getExpr().getValue()
1618+
}
16311619
}
16321620

16331621
/**

0 commit comments

Comments
 (0)