Conversation
src/TrinaryLogic.php
Outdated
| } | ||
|
|
||
| public function and(self ...$operands): self | ||
| public function and(self $operand, self ...$rest): self |
There was a problem hiding this comment.
I think this needs to be
public function and(?self $operand = null, self ...$rest): self
because previously $operands could be a empty array (so no args given to and when invoked via splat
$trinary->and(...$moreTrinaries))
|
one bug in |
|
Sorry if I miss something obvious, but what's the point of keeping the $registry static with the addition of the new $YES $NO $MAYBE? Isn't it fully redundant now? |
|
This is really nice! I welcome your low-level knowledge like this here 😊 |
|
@kaja47 are you still working on this, or should I finish it? thank you |
- Split variadic arguments for and() and or(). Common case of single argument doesn't allocate an array.
- Add static fields mirroring $registry to skip one level of indirection.
- Numeric values chosen that & and | is the same as min and max. and()/or() optimized accordingly.
- Inline trivial create() method.
- Remove one unnecessary access to registry in method create().
this loop runs 1.8x faster (php 8.4.16, jit off)
$t = TrinaryLogic::createYes();
for ($i = 10_000_000; $i--;) {
$t = $t->and(TrinaryLogic::createYes());
}
before: 1.125 s
now: 0.616 s
|
verified the benchmark locally this PR vs. 2.1.x |
|
This pull request has been marked as ready for review. |
|
Thank you! |
|
Thank you @kaja47 |
this loop runs 1.8x faster (php 8.4.16, jit off)
$t = TrinaryLogic::createYes();
for ($i = 10_000_000; $i--;) {
$t = $t->and(TrinaryLogic::createYes());
}
before: 1.125 s
now: 0.616 s