-
Notifications
You must be signed in to change notification settings - Fork 8k
Add consumed_args callback optimization and apply to array_reduce() for carry to improve performance #21340
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
base: master
Are you sure you want to change the base?
Add consumed_args callback optimization and apply to array_reduce() for carry to improve performance #21340
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| --TEST-- | ||
| preg_replace_callback(): capture match array refcount stays low during callback | ||
| --FILE-- | ||
| <?php | ||
| var_dump(preg_replace_callback('/(.)(.)(.)/', static function ($matches) { | ||
| debug_zval_dump($matches); | ||
| return ''; | ||
| }, 'abc')); | ||
|
|
||
| var_dump(preg_replace_callback_array(['/(.)(.)(.)/' => static function ($matches) { | ||
| debug_zval_dump($matches); | ||
| return ''; | ||
| }], 'abc')); | ||
| ?> | ||
| --EXPECTF-- | ||
| array(4) packed refcount(2){ | ||
| [0]=> | ||
| string(3) "abc"%s | ||
| [1]=> | ||
| string(1) "a" interned | ||
| [2]=> | ||
| string(1) "b" interned | ||
| [3]=> | ||
| string(1) "c" interned | ||
| } | ||
| string(0) "" | ||
| array(4) packed refcount(2){ | ||
| [0]=> | ||
| string(3) "abc"%s | ||
| [1]=> | ||
| string(1) "a" interned | ||
| [2]=> | ||
| string(1) "b" interned | ||
| [3]=> | ||
| string(1) "c" interned | ||
| } | ||
| string(0) "" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| --TEST-- | ||
| array_reduce(): accumulator refcount stays low during callback | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $result = array_reduce([1, 2, 3], function ($acc, $val) { | ||
| debug_zval_dump($acc); | ||
| $acc[] = $val; | ||
| return $acc; | ||
| }, []); | ||
|
|
||
| debug_zval_dump($result); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| array(0) interned { | ||
| } | ||
| array(1) packed refcount(2){ | ||
| [0]=> | ||
| int(1) | ||
| } | ||
|
Comment on lines
+18
to
+21
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm surprised this has a refcount of 2, maybe use the new function as I guess debug_zval_dump increases the refcount?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, exactly, debug_zval_dump increases the refcount. |
||
| array(2) packed refcount(2){ | ||
| [0]=> | ||
| int(1) | ||
| [1]=> | ||
| int(2) | ||
| } | ||
| array(3) packed refcount(2){ | ||
| [0]=> | ||
| int(1) | ||
| [1]=> | ||
| int(2) | ||
| [2]=> | ||
| int(3) | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.