Skip to content

Commit 2712866

Browse files
committed
Faster TrinaryLogic::maxMin()
1 parent 001d465 commit 2712866

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/TrinaryLogic.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,15 @@ public static function lazyExtremeIdentity(
240240
*/
241241
public static function maxMin(self ...$operands): self
242242
{
243-
if ($operands === []) {
244-
throw new ShouldNotHappenException();
243+
$max = self::NO;
244+
$min = self::YES;
245+
foreach ($operands as $operand) {
246+
$max |= $operand->value;
247+
$min &= $operand->value;
245248
}
246-
$operandValues = array_column($operands, 'value');
247-
return self::create(max($operandValues) > self::MAYBE ? self::YES : min($operandValues));
249+
$maxMin = $max === self::YES ? self::YES : $min;
250+
251+
return self::$registry[$maxMin] ??= new self($maxMin);
248252
}
249253

250254
/**

0 commit comments

Comments
 (0)