Avoid dynamic_cast for classes with no children, bug1021.

Signed-off-by: Wilson Snyder <wsnyder@wsnyder.org>
This commit is contained in:
Johan Bjork 2016-01-06 20:47:44 -05:00 committed by Wilson Snyder
parent b738d1960a
commit 340cc02171
2 changed files with 14 additions and 2 deletions

View File

@ -3,6 +3,11 @@ Revision history for Verilator
The contributors that suggested a given feature are shown in []. [by ...]
indicates the contributor was also the author of the fix; Thanks!
* Verilator 3.881 devel
**** Internal Verilation-time performance enhancements, bug1021. [Johan Bjork]
* Verilator 3.880 2015-12-19
*** Support display %u, %v, %p, %z, bug989. [Johan Bjork]

View File

@ -248,8 +248,15 @@ sub write_impl {
my $fh = open_file(@_);
foreach my $type (sort (keys %Classes)) {
next if $type eq "Node"; # Special, just a return (this);
printf $fh "inline Ast%-16s AstNode::cast${type}() { return (dynamic_cast<Ast${type}*>(this)); }\n"
,$type."*";
# For performance, prefer static_cast where we can
if (children_of($type)) {
printf $fh "inline Ast%-16s AstNode::cast${type}() { return (dynamic_cast<Ast${type}*>(this)); }\n"
,$type."*";
} else {
my $ucType = uc $type;
printf $fh "inline Ast%-16s AstNode::cast${type}() { return (this && this->type() == AstType::at${ucType}) ? static_cast<Ast${type}*>(this) : NULL; }\n"
,$type."*";
}
}
$fh->close();
}