From 2712866ed867c9af3dbfe91c464e2313c0b6af30 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 25 Feb 2026 15:46:39 +0100 Subject: [PATCH 1/3] Faster TrinaryLogic::maxMin() --- src/TrinaryLogic.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/TrinaryLogic.php b/src/TrinaryLogic.php index 09c7989601..ce66a54020 100644 --- a/src/TrinaryLogic.php +++ b/src/TrinaryLogic.php @@ -240,11 +240,15 @@ public static function lazyExtremeIdentity( */ public static function maxMin(self ...$operands): self { - if ($operands === []) { - throw new ShouldNotHappenException(); + $max = self::NO; + $min = self::YES; + foreach ($operands as $operand) { + $max |= $operand->value; + $min &= $operand->value; } - $operandValues = array_column($operands, 'value'); - return self::create(max($operandValues) > self::MAYBE ? self::YES : min($operandValues)); + $maxMin = $max === self::YES ? self::YES : $min; + + return self::$registry[$maxMin] ??= new self($maxMin); } /** From 39f4e2fd27ae2490b03d16950ec4250b1e1dba79 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 25 Feb 2026 15:53:07 +0100 Subject: [PATCH 2/3] added back exception --- src/TrinaryLogic.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/TrinaryLogic.php b/src/TrinaryLogic.php index ce66a54020..131a54b154 100644 --- a/src/TrinaryLogic.php +++ b/src/TrinaryLogic.php @@ -240,6 +240,10 @@ public static function lazyExtremeIdentity( */ public static function maxMin(self ...$operands): self { + if ($operands === []) { + throw new ShouldNotHappenException(); + } + $max = self::NO; $min = self::YES; foreach ($operands as $operand) { From 2a92088fb524c79bde577ccb6eaab57c5ac656b3 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 25 Feb 2026 16:06:24 +0100 Subject: [PATCH 3/3] Faster TrinaryLogic::lazyMaxMin() --- src/TrinaryLogic.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/TrinaryLogic.php b/src/TrinaryLogic.php index 131a54b154..96f3baa7b3 100644 --- a/src/TrinaryLogic.php +++ b/src/TrinaryLogic.php @@ -265,17 +265,17 @@ public static function lazyMaxMin( callable $callback, ): self { - $results = []; + $min = self::YES; foreach ($objects as $object) { $result = $callback($object); if ($result->value === self::YES) { return $result; } - $results[] = $result; + $min &= $result->value; } - return self::maxMin(...$results); + return self::$registry[$min] ??= new self($min); } public function negate(): self