Req #76827 [Opn->Asn]: Introduce a new function struncate or some such

From: Date: Fri, 31 Aug 2018 18:03:49 +0000
Subject: Req #76827 [Opn->Asn]: Introduce a new function struncate or some such
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-216838@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76827&edit=1 ID: 76827 User updated by: zjz at zjz dot name Reported by: zjz at zjz dot name Summary: Introduce a new function struncate or some such -Status: Open +Status: Assigned Type: Feature/Change Request Package: Performance problem PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Let me try to offer a patch on Github. Previous Comments: ------------------------------------------------------------------------ [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; } ------------------------------------------------------------------------ [2018-08-31 10:34:01] zjz at zjz dot name Well. Let me try to look into the C code and then gives some code example to explain what I said. ------------------------------------------------------------------------ [2018-08-31 09:56:40] zjz at zjz dot name $str = substr($str, 0 , -1); first makes a new string by the truncated length, and then frees the original string, which seems to me uncessary. As to why I suggest this new function with a reference parameter, **I didn't AT ALL try to mean that referencing itself is more effient**, but I just meant in the new function, **something magic** can be done in C code in the new function, so that the original string can be **directly** truncated, without making a new truncated string in another place at first, and then freeing the original one, which is uncessary. ------------------------------------------------------------------------ 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

« previous php.bugs (#216838) next »