Edit report at https://bugs.php.net/bug.php?id=76827&edit=1
ID: 76827
Updated by: krakjoe@php.net
Reported by: zjz at zjz dot name
Summary: Introduce a new function struncate or some such
-Status: Assigned
+Status: Wont fix
Type: Feature/Change Request
Package: Performance problem
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
The conversation surrounding this lead me to close the PR, so I'm closing the bug too. It
appears we're not really willing to implement the thing requested, there were problems with the
implementation, and the other ideas discussed didn't seem optimal either.
Looks like a dead end.
Previous Comments:
------------------------------------------------------------------------
[2020-10-21 16:44:52] cmb@php.net
The following pull request has been associated:
Patch Name: Fix #76827: Introduce a new function str_truncate to make fast truncation
On GitHub: https://github.com/php/php-src/pull/3483
Patch: https://github.com/php/php-src/pull/3483.patch
------------------------------------------------------------------------
[2018-08-31 18:03:49] zjz at zjz dot name
Let me try to offer a patch on Github.
------------------------------------------------------------------------
[2018-08-31 11:09:19] zjz at zjz dot name
Strictly speaking, it doesn't have to be a reference to be passed to struncate at all, since
str->len = len; or some similar code can do the job anyway, regardless of whether the parameter
is a reference or not.
But I'd like to suggest the parameter in the new function to be a reference, otherwise it
can't reflect the fact that the parameter value will be changed(in other words, it's
length would be changed), and would make the user confused.
------------------------------------------------------------------------
[2018-08-31 10:47:45] zjz at zjz dot name
I think it's far more effient than substr when the new string is still very long, after being
truncated, isn't it?
------------------------------------------------------------------------
[2018-08-31 10:39:09] zjz at zjz dot name
The general idea I suggested is directly modifying the **len** value of the str:
TBC, I am not familar with PHP source code, so this code I write here can't be the exactly
formal code, but simply demostrates the general idea I meant:
PHP_FUNCTION(struncate)
{
zend_string* str;
zend_long len;
int argc = ZEND_NUM_ARGS();
ZEND_PARSE_PARAMETERS_START(...)
Z_PARAM_STR(str)
Z_PARAM_LONG(len)
ZEND_PARSE_PARAMETERS_END();
str->len = len;
}
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=76827
--
Edit this bug report at https://bugs.php.net/bug.php?id=76827&edit=1