authorgravatar for 102751849+Fri3dNstuff@users.noreply.github.comFri3dNstuff <102751849+Fri3dNstuff@users.noreply.github.com> 2024-11-25 00:29:44+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-11-24 14:29:44-08:00
logb2030cb9abf73886e1c896ee8d56a3156b6fd3c2
tree5a9a4e42176fc0c048ea82447a7a973dfa87eeb1
parentc894ac09a31380319ba9cfdc82025fcc614a8cc0
signaturebadge-check Signed by PGP key B5690EEEBB952194

`std.meta.eql`: use `==` directly when comparing `packed struct`s (#21982)


1 files changed, 4 insertions(+), 2 deletions(-)

lib/std/meta.zig+4-2
......@@ -737,13 +737,15 @@ test TagPayload {
737737 try testing.expect(MovedEvent == @TypeOf(e.Moved));
738738}
739739
740/// Compares two of any type for equality. Containers are compared on a field-by-field basis,
741/// where possible. Pointers are not followed.
740/// Compares two of any type for equality. Containers that do not support comparison
741/// on their own are compared on a field-by-field basis. Pointers are not followed.
742742pub fn eql(a: anytype, b: @TypeOf(a)) bool {
743743 const T = @TypeOf(a);
744744
745745 switch (@typeInfo(T)) {
746746 .@"struct" => |info| {
747 if (info.layout == .@"packed") return a == b;
748
747749 inline for (info.fields) |field_info| {
748750 if (!eql(@field(a, field_info.name), @field(b, field_info.name))) return false;
749751 }