mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 10:08:20 +00:00
record field initialization optimization: do coercions at compile-time if applicable
This commit is contained in:
parent
b3dacce3e1
commit
88ef6cb5b6
1 changed files with 6 additions and 0 deletions
|
@ -1071,6 +1071,12 @@ void RecordType::AddField(unsigned int field, const TypeDecl* td) {
|
|||
init = std::make_shared<detail::DirectFieldInit>(zv);
|
||||
}
|
||||
|
||||
else if ( def_expr->Tag() == detail::EXPR_ARITH_COERCE &&
|
||||
(def_expr->GetOp1()->IsZero() || def_expr->GetOp1()->IsOne()) ) {
|
||||
auto zv = ZVal(def_expr->Eval(nullptr), type);
|
||||
init = std::make_shared<detail::DirectFieldInit>(zv);
|
||||
}
|
||||
|
||||
else {
|
||||
auto efi = std::make_shared<detail::ExprFieldInit>(def_expr, type);
|
||||
creation_inits.emplace_back(field, std::move(efi));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue