aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/compiler
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2025-01-17 10:28:16 +0100
committerDmitry Vyukov <dvyukov@google.com>2025-01-17 10:02:07 +0000
commit5d04aae8969f6c72318ce0a4cde4f027766b1a55 (patch)
tree8f1b632847c431407090f0fe1335522ff2195a37 /pkg/compiler
parentf9e07a6e597b68d3397864e6ee4550f9065c3518 (diff)
all: use min/max functions
They are shorter, more readable, and don't require temp vars.
Diffstat (limited to 'pkg/compiler')
-rw-r--r--pkg/compiler/gen.go12
-rw-r--r--pkg/compiler/types.go9
2 files changed, 5 insertions, 16 deletions
diff --git a/pkg/compiler/gen.go b/pkg/compiler/gen.go
index fb406b815..81e8f83bc 100644
--- a/pkg/compiler/gen.go
+++ b/pkg/compiler/gen.go
@@ -284,9 +284,7 @@ func (comp *compiler) layoutUnion(t *prog.UnionType) {
" which is less than field %v size %v",
structNode.Name.Name, sizeAttr, fld.Type.Name(), sz)
}
- if t.TypeSize < sz {
- t.TypeSize = sz
- }
+ t.TypeSize = max(t.TypeSize, sz)
}
if hasSize {
t.TypeSize = sizeAttr
@@ -313,9 +311,7 @@ func (comp *compiler) layoutStruct(t *prog.StructType) {
size = 0
}
size += f.Size()
- if t.TypeSize < size {
- t.TypeSize = size
- }
+ t.TypeSize = max(t.TypeSize, size)
}
sizeAttr, hasSize := attrs[attrSize]
if hasSize {
@@ -348,9 +344,7 @@ func (comp *compiler) layoutStructFields(t *prog.StructType, varlen, packed bool
fieldAlign := uint64(1)
if !packed {
fieldAlign = f.Alignment()
- if structAlign < fieldAlign {
- structAlign = fieldAlign
- }
+ structAlign = max(structAlign, fieldAlign)
}
fullBitOffset := byteOffset*8 + bitOffset
var fieldOffset uint64
diff --git a/pkg/compiler/types.go b/pkg/compiler/types.go
index 906af199c..ae0864725 100644
--- a/pkg/compiler/types.go
+++ b/pkg/compiler/types.go
@@ -1007,9 +1007,7 @@ func init() {
case *prog.UnionType:
typ1.Fields = fields
for _, f := range fields {
- if a := f.Type.Alignment(); typ1.TypeAlign < a {
- typ1.TypeAlign = a
- }
+ typ1.TypeAlign = max(typ1.TypeAlign, f.Type.Alignment())
}
case *prog.StructType:
typ1.Fields = fields
@@ -1028,10 +1026,7 @@ func init() {
typ1.TypeAlign = 1
} else {
for _, f := range fields {
- a := f.Type.Alignment()
- if typ1.TypeAlign < a {
- typ1.TypeAlign = a
- }
+ typ1.TypeAlign = max(typ1.TypeAlign, f.Type.Alignment())
}
}
}