Skip to content

Commit cf10b53

Browse files
committed
EssentialTypes: Improve performance of Rule 10.5
This improves the performance of Rule 10.5 by computing all the types of the cast first, before determining whether they were invalid. Previously the join orderer found the essential type category of the "from" type, then joined that will invalid type categories, then joined that with all expressions of that type before filtering down to the cast.
1 parent 332dee2 commit cf10b53

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

c/misra/src/rules/RULE-10-5/InappropriateEssentialTypeCast.ql

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,23 @@ predicate isIncompatibleEssentialTypeCast(EssentialTypeCategory fromCat, Essenti
4949
]
5050
}
5151

52+
predicate isCastTypes(
53+
Cast c, Type essentialFromType, Type essentialToType, EssentialTypeCategory fromCategory,
54+
EssentialTypeCategory toCategory
55+
) {
56+
essentialFromType = getEssentialTypeBeforeConversions(c.getExpr()) and
57+
essentialToType = c.getType() and
58+
fromCategory = getEssentialTypeCategory(essentialFromType) and
59+
toCategory = getEssentialTypeCategory(essentialToType)
60+
}
61+
5262
from
5363
Cast c, Type essentialFromType, Type essentialToType, EssentialTypeCategory fromCategory,
5464
EssentialTypeCategory toCategory, string message
5565
where
5666
not isExcluded(c, EssentialTypesPackage::inappropriateEssentialTypeCastQuery()) and
5767
not c.isImplicit() and
58-
essentialFromType = getEssentialTypeBeforeConversions(c.getExpr()) and
59-
essentialToType = c.getType() and
60-
fromCategory = getEssentialTypeCategory(essentialFromType) and
61-
toCategory = getEssentialTypeCategory(essentialToType) and
68+
isCastTypes(c, essentialFromType, essentialToType, fromCategory, toCategory) and
6269
isIncompatibleEssentialTypeCast(fromCategory, toCategory) and
6370
(
6471
if fromCategory = EssentiallyEnumType() and toCategory = EssentiallyEnumType()

0 commit comments

Comments
 (0)