diff options
| author | Fri3dNstuff <102751849+Fri3dNstuff@users.noreply.github.com> | 2024-11-25 00:29:44 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-24 14:29:44 -0800 |
| commit | b2030cb9abf73886e1c896ee8d56a3156b6fd3c2 (patch) | |
| tree | 5a9a4e42176fc0c048ea82447a7a973dfa87eeb1 /lib/std/meta.zig | |
| parent | c894ac09a31380319ba9cfdc82025fcc614a8cc0 (diff) | |
| download | zig-b2030cb9abf73886e1c896ee8d56a3156b6fd3c2.tar.gz zig-b2030cb9abf73886e1c896ee8d56a3156b6fd3c2.zip | |
`std.meta.eql`: use `==` directly when comparing `packed struct`s (#21982)
Diffstat (limited to 'lib/std/meta.zig')
| -rw-r--r-- | lib/std/meta.zig | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/std/meta.zig b/lib/std/meta.zig index 0ea83bb11e..44bfb65f8a 100644 --- a/lib/std/meta.zig +++ b/lib/std/meta.zig @@ -737,13 +737,15 @@ test TagPayload { try testing.expect(MovedEvent == @TypeOf(e.Moved)); } -/// Compares two of any type for equality. Containers are compared on a field-by-field basis, -/// where possible. Pointers are not followed. +/// Compares two of any type for equality. Containers that do not support comparison +/// on their own are compared on a field-by-field basis. Pointers are not followed. pub fn eql(a: anytype, b: @TypeOf(a)) bool { const T = @TypeOf(a); switch (@typeInfo(T)) { .@"struct" => |info| { + if (info.layout == .@"packed") return a == b; + inline for (info.fields) |field_info| { if (!eql(@field(a, field_info.name), @field(b, field_info.name))) return false; } |
