mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-31 15:22:21 -04:00
coccinelle: misc: minmax: improve performance when no candidate exists
The rules that report an opencoded min() or max() search every function body, even when the file contains nothing to find. To avoid this, collect the candidates first and run the search only when one exists. A candidate is any conditional expression whose condition is a comparison. Every opencoded min() or max() is also a candidate, so the same opportunities are reported as before and the output does not change. A report-mode run over every .c file in the tree produces identical output. Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
This commit is contained in:
committed by
Julia Lawall
parent
bf2fe566a8
commit
b32cf68d78
@@ -17,7 +17,21 @@ virtual org
|
||||
virtual context
|
||||
virtual patch
|
||||
|
||||
@rmax depends on !patch@
|
||||
@max_candidate@
|
||||
expression E1, E2, E3, E4;
|
||||
binary operator cmp = {>, >=};
|
||||
@@
|
||||
|
||||
(E1 cmp E2 ? E3 : E4)
|
||||
|
||||
@min_candidate@
|
||||
expression E1, E2, E3, E4;
|
||||
binary operator cmp = {<, <=};
|
||||
@@
|
||||
|
||||
(E1 cmp E2 ? E3 : E4)
|
||||
|
||||
@rmax depends on !patch && max_candidate@
|
||||
identifier func;
|
||||
expression x, y;
|
||||
binary operator cmp = {>, >=};
|
||||
@@ -51,7 +65,7 @@ func(...)
|
||||
}
|
||||
|
||||
// Ignore errcode returns.
|
||||
@errcode@
|
||||
@errcode depends on min_candidate@
|
||||
position p;
|
||||
identifier func;
|
||||
expression x;
|
||||
@@ -65,7 +79,7 @@ func(...)
|
||||
...>
|
||||
}
|
||||
|
||||
@rmin depends on !patch@
|
||||
@rmin depends on !patch && min_candidate@
|
||||
identifier func;
|
||||
expression x, y;
|
||||
binary operator cmp = {<, <=};
|
||||
@@ -98,7 +112,7 @@ func(...)
|
||||
...>
|
||||
}
|
||||
|
||||
@pmax depends on patch@
|
||||
@pmax depends on patch && max_candidate@
|
||||
identifier func;
|
||||
expression x, y;
|
||||
binary operator cmp = {>=, >};
|
||||
@@ -131,7 +145,7 @@ func(...)
|
||||
...>
|
||||
}
|
||||
|
||||
@pmin depends on patch@
|
||||
@pmin depends on patch && min_candidate@
|
||||
identifier func;
|
||||
expression x, y;
|
||||
binary operator cmp = {<=, <};
|
||||
|
||||
Reference in New Issue
Block a user