|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2018-08-31 08:27 UTC] zjz at zjz dot name
Description: ------------ Please consider introducing a new function |struncate| or some such to resolve the performance problem of truncate a very long string to a slightly shorter one. For example, suppose the user wants to truncate a 50000 byte string to a 49999 byte string(i.e. to delete the last character), and **the untruncated one is no longer in use**. Right now the user has to write code as such: $str = substr($str, 0, -1); However, this is silly, it is rather bad in performance when the string copying is not necessary as the untruncated one is no longer in use as mentioned above. So I'd like to suggest adding a new function |struncate|, which receives two parameters, one is a reference of a string to be truncated, the other is the truncated length: function struncate(&$string, $length) PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 14 13:00:01 2025 UTC |
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; }