From 958c9a4815778c704f82381e3979214145cf3aad Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Tue, 7 Mar 2023 23:17:03 +0000 Subject: [PATCH 1/2] Rule 20.12: Improve performance This commit optimizes the from-where-select clause of this query, which was highlighted as one of the slowest predicates for our C query suites. This commit makes the following changes: * Avoid repetition of `m.getParameter(i)`, which caused a cross product * Change the way we identify "further expanded macro" * Modify the isExcluded predicate to reference the macro invocation not the macro. --- .../rules/RULE-20-12/MacroParameterUsedAsHashOperand.ql | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/c/misra/src/rules/RULE-20-12/MacroParameterUsedAsHashOperand.ql b/c/misra/src/rules/RULE-20-12/MacroParameterUsedAsHashOperand.ql index 779c14176c..6a66afb74b 100644 --- a/c/misra/src/rules/RULE-20-12/MacroParameterUsedAsHashOperand.ql +++ b/c/misra/src/rules/RULE-20-12/MacroParameterUsedAsHashOperand.ql @@ -19,7 +19,7 @@ import codingstandards.cpp.Macro from FunctionLikeMacro m, MacroInvocation mi, int i, string expanded, string param where - not isExcluded(m, Preprocessor2Package::macroParameterUsedAsHashOperandQuery()) and + not isExcluded(mi, Preprocessor2Package::macroParameterUsedAsHashOperandQuery()) and mi = m.getAnInvocation() and param = m.getParameter(i) and ( @@ -31,9 +31,6 @@ where // This check ensure there is an expansion that is used. expanded = mi.getExpandedArgument(i) and not expanded = "" and - exists(Macro furtherExpandedMacro | - mi.getUnexpandedArgument(i).matches(furtherExpandedMacro.getName() + "%") - ) + not mi.getUnexpandedArgument(i) = mi.getExpandedArgument(i) select m, - "Macro " + m.getName() + " contains use of parameter " + m.getParameter(i) + - " used in multiple contexts." + "Macro " + m.getName() + " contains use of parameter " + param + " used in multiple contexts." From d9188c79dbebc7e98a98974aa83777cc7ad273f9 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Tue, 7 Mar 2023 23:25:06 +0000 Subject: [PATCH 2/2] Rule 20.12: Add a perf change note. --- change_notes/2023-03-07-20-12-perf.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 change_notes/2023-03-07-20-12-perf.md diff --git a/change_notes/2023-03-07-20-12-perf.md b/change_notes/2023-03-07-20-12-perf.md new file mode 100644 index 0000000000..b42c81ebce --- /dev/null +++ b/change_notes/2023-03-07-20-12-perf.md @@ -0,0 +1 @@ + * `Rule 20.12` - the performance of this rule has been improved. \ No newline at end of file