mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-28 21:07:56 +00:00
parser: simplify prefix comparison code
The prefix comparison doesn't need to do as many operations as it is doing, and the operator< can be based on the cmp() fn further reducing the chance that the code will get out of sync if prefixes are changed. Signed-off-by: John Johansen <john.johansen@canonical.com>
This commit is contained in:
parent
cd95d46397
commit
abc18e45a4
@ -246,14 +246,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int cmp(prefixes const &rhs) const {
|
int cmp(prefixes const &rhs) const {
|
||||||
if ((uint) audit < (uint) rhs.audit)
|
int tmp = (int) audit - (int) rhs.audit;
|
||||||
return -1;
|
if (tmp != 0)
|
||||||
if ((uint) audit > (uint) rhs.audit)
|
return tmp;
|
||||||
return 1;
|
tmp = (int) rule_mode - (int) rhs.rule_mode;
|
||||||
if ((uint) rule_mode < (uint) rhs.rule_mode)
|
if (tmp != 0)
|
||||||
return -1;
|
return tmp;
|
||||||
if ((uint) rule_mode > (uint) rhs.rule_mode)
|
|
||||||
return 1;
|
|
||||||
if ((uint) owner < (uint) rhs.owner)
|
if ((uint) owner < (uint) rhs.owner)
|
||||||
return -1;
|
return -1;
|
||||||
if ((uint) owner > (uint) rhs.owner)
|
if ((uint) owner > (uint) rhs.owner)
|
||||||
@ -262,11 +260,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool operator<(prefixes const &rhs) const {
|
bool operator<(prefixes const &rhs) const {
|
||||||
if ((uint) audit < (uint) rhs.audit)
|
if (cmp(rhs) < 0)
|
||||||
return true;
|
|
||||||
if ((uint) rule_mode < (uint) rhs.rule_mode)
|
|
||||||
return true;
|
|
||||||
if ((uint) owner < (uint) rhs.owner)
|
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user