mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-22 10:07:12 +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 {
|
||||
if ((uint) audit < (uint) rhs.audit)
|
||||
return -1;
|
||||
if ((uint) audit > (uint) rhs.audit)
|
||||
return 1;
|
||||
if ((uint) rule_mode < (uint) rhs.rule_mode)
|
||||
return -1;
|
||||
if ((uint) rule_mode > (uint) rhs.rule_mode)
|
||||
return 1;
|
||||
int tmp = (int) audit - (int) rhs.audit;
|
||||
if (tmp != 0)
|
||||
return tmp;
|
||||
tmp = (int) rule_mode - (int) rhs.rule_mode;
|
||||
if (tmp != 0)
|
||||
return tmp;
|
||||
if ((uint) owner < (uint) rhs.owner)
|
||||
return -1;
|
||||
if ((uint) owner > (uint) rhs.owner)
|
||||
@ -262,11 +260,7 @@ public:
|
||||
}
|
||||
|
||||
bool operator<(prefixes const &rhs) const {
|
||||
if ((uint) audit < (uint) rhs.audit)
|
||||
return true;
|
||||
if ((uint) rule_mode < (uint) rhs.rule_mode)
|
||||
return true;
|
||||
if ((uint) owner < (uint) rhs.owner)
|
||||
if (cmp(rhs) < 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user