Skip to content

Commit

Permalink
Optimize traits.d by factoring out two common sub-expressions when ev…
Browse files Browse the repository at this point in the history
…aluating the builtin traits isFinalClass and isTemplate
  • Loading branch information
nordlow committed Aug 25, 2024
1 parent 90c4145 commit 2370e2c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions compiler/src/dmd/traits.d
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,19 @@ Expression semanticTraits(TraitsExp e, Scope* sc)
}
if (e.ident == Id.isAbstractClass)
{
return isTypeX(t => t.toBasetype().isTypeClass() &&
t.toBasetype().isTypeClass().sym.isAbstract());
return isTypeX((t)
{
auto c = t.toBasetype().isTypeClass();
return c && c.sym.isAbstract();
});
}
if (e.ident == Id.isFinalClass)
{
return isTypeX(t => t.toBasetype().isTypeClass() &&
(t.toBasetype().isTypeClass().sym.storage_class & STC.final_) != 0);
return isTypeX((t)
{
const c = t.toBasetype().isTypeClass();
return c && (c.sym.storage_class & STC.final_) != 0;
});
}
if (e.ident == Id.isTemplate)
{
Expand Down

0 comments on commit 2370e2c

Please sign in to comment.