parser: stop using dynamic_cast for prompt permission calculations

Like was done for the other MatchFlags switch to using a node type
instead of dynamic_cast as this will result in a performance
improvement.

Signed-off-by: John Johansen <john.johansen@canonical.com>
This commit is contained in:
John Johansen 2024-12-24 02:37:39 -08:00
parent 002bf1339c
commit 9221d291ec
2 changed files with 6 additions and 2 deletions

View file

@ -245,6 +245,7 @@ ostream &operator<<(ostream &os, Node &node);
#define NODE_TYPE_MATCHFLAG (1 << 18)
#define NODE_TYPE_EXACTMATCHFLAG (1 << 19)
#define NODE_TYPE_DENYMATCHFLAG (1 << 20)
#define NODE_TYPE_PROMPTMATCHFLAG (1 << 21)
/* An abstract node in the syntax tree. */
class Node {
@ -915,7 +916,10 @@ public:
class PromptMatchFlag: public MatchFlag {
public:
PromptMatchFlag(int priority, perm32_t prompt, perm32_t audit): MatchFlag(priority, prompt, audit) {}
PromptMatchFlag(int priority, perm32_t prompt, perm32_t audit): MatchFlag(priority, prompt, audit)
{
type_flags |= NODE_TYPE_PROMPTMATCHFLAG;
}
};

View file

@ -1440,7 +1440,7 @@ int accept_perms(NodeVec *state, perms_t &perms, bool filedfa)
} else if (match->is_type(NODE_TYPE_DENYMATCHFLAG)) {
perms.deny |= match->perms;
perms.quiet |= match->audit;
} else if (dynamic_cast<PromptMatchFlag *>(match)) {
} else if (match->is_type(NODE_TYPE_PROMPTMATCHFLAG)) {
perms.prompt |= match->perms;
perms.audit |= match->audit;
} else {