[apparmor] [PATCH 08/20] Rework tests against Epsnodes to compare to the singleton

John Johansen john.johansen at canonical.com
Fri Nov 5 05:51:04 GMT 2010


Dynamic casts are slower than plain comparisons so rework epsnode comparison
to use comparisons to the singleton epsnode instead of dynamic_casts.

Signed-off-by: John Johansen <john.johansen at canonical.com>
---
 parser/libapparmor_re/regexp.y |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/parser/libapparmor_re/regexp.y b/parser/libapparmor_re/regexp.y
index bfd74c6..b16af06 100644
--- a/parser/libapparmor_re/regexp.y
+++ b/parser/libapparmor_re/regexp.y
@@ -568,11 +568,10 @@ void normalize_tree(Node *t, int dir)
 		return;
 
 	for (;;) {
-		if (!dynamic_cast<EpsNode *>(t->child[!dir]) &&
-		    ((dynamic_cast<AltNode *>(t) &&
-		      dynamic_cast<EpsNode *>(t->child[dir])) ||
-		     (dynamic_cast<CatNode *>(t) &&
-		      dynamic_cast<EpsNode *>(t->child[dir])))) {
+		if ((&epsnode == t->child[dir]) &&
+		    (&epsnode != t->child[!dir]) &&
+		    (dynamic_cast<AltNode *>(t) ||
+		     dynamic_cast<CatNode *>(t))) {
 			// (E | a) -> (a | E)
 			// Ea -> aE
 			Node *c = t->child[dir];
@@ -740,7 +739,7 @@ static Node *basic_alt_factor(Node *t, int dir)
 static Node *basic_simplify(Node *t, int dir)
 {
 	if (dynamic_cast<CatNode *>(t) &&
-	    dynamic_cast<EpsNode *>(t->child[!dir])) {
+	    &epsnode == t->child[!dir]) {
 		// aE -> a
 		Node *tmp = t->child[dir];
 		t->child[dir] = NULL;
-- 
1.7.1




More information about the AppArmor mailing list