From 16dd7e365af22aa500070fb5c3b4cdf7139db1d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ferreira?= Date: Sun, 16 Oct 2022 20:25:44 +0100 Subject: [PATCH] chore(sumtype): avoid quadratic memory complexity on opEquals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luís Ferreira --- std/sumtype.d | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/std/sumtype.d b/std/sumtype.d index ee2d73a1233..715a4119404 100644 --- a/std/sumtype.d +++ b/std/sumtype.d @@ -714,16 +714,24 @@ public: { static if (is(This == Rhs)) { - return AliasSeq!(this, rhs).match!((ref value, ref rhsValue) { - static if (is(typeof(value) == typeof(rhsValue))) - { - return value == rhsValue; - } - else + final switch(tag) + { + static foreach(idx, T; Types) { - return false; + case idx: + final switch (rhs.tag) + { + static foreach(ridx, U; typeof(rhs).Types) + { + case ridx: + static if (is(immutable T == immutable U)) + return get!T == rhs.get!U; + else + return false; + } + } } - }); + } } else {