authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-20 17:29:46-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-21 14:48:40-07:00
log51b1a2a6cb1a48260a37c407adbb4b796cf58a54
tree998c3919cf7b06a920a59ab4ff54e33f433dabf6
parent5ea3de55c4ca89b1f9fd95e40e6dd17cc89efe23

Alignment: min/minStrict max/maxStrict

Carve out a path forward for being a little bit more intentional about handling "default" alignment values.

1 files changed, 19 insertions(+), 3 deletions(-)

src/InternPool.zig+19-3
...@@ -3178,16 +3178,32 @@ pub const Alignment = enum(u6) {...@@ -3178,16 +3178,32 @@ pub const Alignment = enum(u6) {
3178 }3178 }
31793179
3180 /// Treats `none` as zero.3180 /// Treats `none` as zero.
3181 /// This matches previous behavior of using `@max` directly on byte units.
3182 /// Prefer `maxStrict` if possible.
3181 pub fn max(lhs: Alignment, rhs: Alignment) Alignment {3183 pub fn max(lhs: Alignment, rhs: Alignment) Alignment {
3182 if (lhs == .none) return rhs;3184 if (lhs == .none) return rhs;
3183 if (rhs == .none) return lhs;3185 if (rhs == .none) return lhs;
3186 return maxStrict(lhs, rhs);
3187 }
3188
3189 pub fn maxStrict(lhs: Alignment, rhs: Alignment) Alignment {
3190 assert(lhs != .none);
3191 assert(rhs != .none);
3184 return @enumFromInt(@max(@intFromEnum(lhs), @intFromEnum(rhs)));3192 return @enumFromInt(@max(@intFromEnum(lhs), @intFromEnum(rhs)));
3185 }3193 }
31863194
3187 /// Treats `none` as maximum value.3195 /// Treats `none` as zero.
3196 /// This matches previous behavior of using `@min` directly on byte units.
3197 /// Prefer `minStrict` if possible.
3188 pub fn min(lhs: Alignment, rhs: Alignment) Alignment {3198 pub fn min(lhs: Alignment, rhs: Alignment) Alignment {
3189 if (lhs == .none) return rhs;3199 if (lhs == .none) return lhs;
3190 if (rhs == .none) return lhs;3200 if (rhs == .none) return rhs;
3201 return minStrict(lhs, rhs);
3202 }
3203
3204 pub fn minStrict(lhs: Alignment, rhs: Alignment) Alignment {
3205 assert(lhs != .none);
3206 assert(rhs != .none);
3191 return @enumFromInt(@min(@intFromEnum(lhs), @intFromEnum(rhs)));3207 return @enumFromInt(@min(@intFromEnum(lhs), @intFromEnum(rhs)));
3192 }3208 }
31933209