-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimize with defer logic #21
Conversation
1. optimize destruct method 2. return SplStack Instance
add examples for php 7.4
What's the goal of this pull request? |
less memory useage & higher performance & chain call & better implementation |
Chain callsChain calls look a bit weird to me. I cannot see a big benefit of using defer($_, $callbackA)->push($callbackB); instead of defer($_, $callbackA);
defer($_, $callbackB); Furthermore, why do we have to register 2 callbacks in consecutive lines? Would not be easier to have just: defer($_, function() {
$callbackB();
$callbackA();
}); ? In my opinion, the above code is more explicit and easier to read. I appreciate your effort, but I have to reject this part. DesignI really like your way of making the order of callbacks explicit. while ($this->count() > 0) {
\call_user_func($this->pop());
} If you are ok with reverting "chain calls" from your pull request, I would like to merge it. |
chain calls: I just return the SplStack object on the basis of the original, but i dont think it is recommended to use it like that. so i removed in README |
src/functions.inc.php
Outdated
@@ -9,23 +9,17 @@ | |||
* file that was distributed with this source code. | |||
*/ | |||
|
|||
function defer(?SplStack &$context, callable $callback): void | |||
function defer(?SplStack &$context, callable $callback): SplStack |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot approve changing the header of this function, I explained it in the previous comment:
function defer(?SplStack &$context, callable $callback): SplStack | |
function defer(?SplStack &$context, callable $callback): void |
README.md
Outdated
|
||
// in 7.4+ | ||
// without use statments | ||
defer($_, fn() => print_r([1])); | ||
|
||
// 7.3 - | ||
defer($_, function () { | ||
echo "goodbye\n"; | ||
}); | ||
|
||
defer($_, function () { | ||
echo "...\n"; | ||
}); | ||
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert those changes
No description provided.