diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-09-20 17:29:46 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-09-21 14:48:40 -0700 |
| commit | 51b1a2a6cb1a48260a37c407adbb4b796cf58a54 (patch) | |
| tree | 998c3919cf7b06a920a59ab4ff54e33f433dabf6 /src/InternPool.zig | |
| parent | 5ea3de55c4ca89b1f9fd95e40e6dd17cc89efe23 (diff) | |
| download | zig-51b1a2a6cb1a48260a37c407adbb4b796cf58a54.tar.gz zig-51b1a2a6cb1a48260a37c407adbb4b796cf58a54.zip | |
Alignment: min/minStrict max/maxStrict
Carve out a path forward for being a little bit more intentional about
handling "default" alignment values.
Diffstat (limited to 'src/InternPool.zig')
| -rw-r--r-- | src/InternPool.zig | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/InternPool.zig b/src/InternPool.zig index 2aa4fef448..03eb5994d5 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -3178,16 +3178,32 @@ pub const Alignment = enum(u6) { } /// Treats `none` as zero. + /// This matches previous behavior of using `@max` directly on byte units. + /// Prefer `maxStrict` if possible. pub fn max(lhs: Alignment, rhs: Alignment) Alignment { if (lhs == .none) return rhs; if (rhs == .none) return lhs; + return maxStrict(lhs, rhs); + } + + pub fn maxStrict(lhs: Alignment, rhs: Alignment) Alignment { + assert(lhs != .none); + assert(rhs != .none); return @enumFromInt(@max(@intFromEnum(lhs), @intFromEnum(rhs))); } - /// Treats `none` as maximum value. + /// Treats `none` as zero. + /// This matches previous behavior of using `@min` directly on byte units. + /// Prefer `minStrict` if possible. pub fn min(lhs: Alignment, rhs: Alignment) Alignment { - if (lhs == .none) return rhs; - if (rhs == .none) return lhs; + if (lhs == .none) return lhs; + if (rhs == .none) return rhs; + return minStrict(lhs, rhs); + } + + pub fn minStrict(lhs: Alignment, rhs: Alignment) Alignment { + assert(lhs != .none); + assert(rhs != .none); return @enumFromInt(@min(@intFromEnum(lhs), @intFromEnum(rhs))); } |
