Conversation
staabm
reviewed
Jan 29, 2026
src/TrinaryLogic.php
Outdated
| } | ||
|
|
||
| public function and(self ...$operands): self | ||
| public function and(self $operand, self ...$rest): self |
Contributor
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))
Contributor
|
one bug in |
Contributor
|
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? |
- 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
Member
|
This is really nice! I welcome your low-level knowledge like this here 😊 |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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