lang: add if.likely and if.unlikely

This commit is contained in:
Nigel Tao committed 2023-06-20 18:00:48 +10:00
1 parent 1acd74482a
commit 8916f1b6ea
5 files changed
+32 -8

No files matched your search

+8 -1
View File
@@ -430,12 +430,19 @@ func (g *gen) writeStatementIf(b *buffer, n *a.If, depth uint32) error {
}
for {
prefix, suffix := "", ""
switch n.Likelihood() {
case t.IDLikely:
prefix, suffix = "WUFFS_BASE__LIKELY(", ")"
case t.IDUnlikely:
prefix, suffix = "WUFFS_BASE__UNLIKELY(", ")"
}
condition := buffer(nil)
if err := g.writeExpr(&condition, n.Condition(), false, 0); err != nil {
return err
}
// Calling trimParens avoids clang's -Wparentheses-equality warning.
b.printf("if (%s) {\n", trimParens(condition))
b.printf("if (%s%s%s) {\n", prefix, trimParens(condition), suffix)
for _, o := range n.BodyIfTrue() {
if err := g.writeStatement(b, o, depth); err != nil {
return err