mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
minor optimization of boolean comparisons
This commit is contained in:
parent
e960c29acb
commit
ff7466df6e
2 changed files with 28 additions and 4 deletions
|
@ -1238,10 +1238,28 @@ ExprPtr EqExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
||||||
if ( IsHasElementsTest() )
|
if ( IsHasElementsTest() )
|
||||||
return BuildHasElementsTest()->Reduce(c, red_stmt);
|
return BuildHasElementsTest()->Reduce(c, red_stmt);
|
||||||
|
|
||||||
if ( GetType()->Tag() == TYPE_BOOL && same_singletons(op1, op2) ) {
|
if ( GetType()->Tag() == TYPE_BOOL ) {
|
||||||
bool t = Tag() == EXPR_EQ;
|
if ( same_singletons(op1, op2) ) {
|
||||||
auto res = with_location_of(make_intrusive<ConstExpr>(val_mgr->Bool(t)), this);
|
bool t = Tag() == EXPR_EQ;
|
||||||
return res->Reduce(c, red_stmt);
|
auto res = with_location_of(make_intrusive<ConstExpr>(val_mgr->Bool(t)), this);
|
||||||
|
return res->Reduce(c, red_stmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( op1->GetType()->Tag() == TYPE_BOOL ) {
|
||||||
|
if ( op1->Tag() == EXPR_CONST )
|
||||||
|
std::swap(op1, op2);
|
||||||
|
|
||||||
|
if ( op2->Tag() == EXPR_CONST ) {
|
||||||
|
bool t = Tag() == EXPR_EQ;
|
||||||
|
if ( op2->AsConstExpr()->Value()->IsZero() )
|
||||||
|
t = ! t;
|
||||||
|
if ( t )
|
||||||
|
return op1->Reduce(c, red_stmt);
|
||||||
|
|
||||||
|
auto res = with_location_of(make_intrusive<NotExpr>(op1), this);
|
||||||
|
return res->Reduce(c, red_stmt);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return BinaryExpr::Reduce(c, red_stmt);
|
return BinaryExpr::Reduce(c, red_stmt);
|
||||||
|
|
|
@ -245,6 +245,12 @@ StmtPtr IfStmt::DoReduce(Reducer* c) {
|
||||||
red_e_stmt = cond_red_stmt;
|
red_e_stmt = cond_red_stmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check again for negation given above reductions/replacements.
|
||||||
|
if ( e->Tag() == EXPR_NOT ) {
|
||||||
|
std::swap(s1, s2);
|
||||||
|
e = e->GetOp1();
|
||||||
|
}
|
||||||
|
|
||||||
StmtPtr sl;
|
StmtPtr sl;
|
||||||
|
|
||||||
if ( e->IsConst() ) {
|
if ( e->IsConst() ) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue