Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:21956 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64237 invoked by uid 1010); 20 Feb 2006 10:57:37 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 64220 invoked from network); 20 Feb 2006 10:57:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Feb 2006 10:57:37 -0000 X-Host-Fingerprint: 212.77.105.136 it.wp-sa.pl Received: from ([212.77.105.136:11685] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id A6/1B-45151-0A0A9F34 for ; Mon, 20 Feb 2006 05:57:36 -0500 Message-ID: To: internals@lists.php.net Date: Mon, 20 Feb 2006 11:57:33 +0100 User-Agent: Mozilla Thunderbird 1.0.7-1.4.1.centos4 (X11/20051007) X-Accept-Language: en-us, en MIME-Version: 1.0 References: <63.BA.45151.ACC99F34@pb1.pair.com> In-Reply-To: <63.BA.45151.ACC99F34@pb1.pair.com> Content-Type: multipart/mixed; boundary="------------020604060900080400010702" X-Posted-By: 212.77.105.136 Subject: Re: Extensive reallocations in strtr, str_replace and implode From: wmeler@wp.pl (Wojtek Meler) --------------020604060900080400010702 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Missing parentheses... Regards, Wojtek Meler --------------020604060900080400010702 Content-Type: text/x-patch; name="string.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="string.patch" Index: string.c =================================================================== RCS file: /repository/php-src/ext/standard/string.c,v retrieving revision 1.333.2.52.2.3 diff -u -r1.333.2.52.2.3 string.c --- string.c 1 Jan 2006 13:46:58 -0000 1.333.2.52.2.3 +++ string.c 20 Feb 2006 10:55:22 -0000 @@ -829,12 +829,14 @@ HashPosition pos; smart_str implstr = {0}; int numelems, i = 0; + size_t newlen; //used by smart_str_alloc numelems = zend_hash_num_elements(Z_ARRVAL_P(arr)); if(numelems == 0) { RETURN_EMPTY_STRING(); } + smart_str_alloc((&implstr),numelems*Z_STRLEN_P(delim),0); zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos); while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), @@ -846,6 +848,8 @@ smart_str_appendl(&implstr, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); if (++i != numelems) { smart_str_appendl(&implstr, Z_STRVAL_P(delim), Z_STRLEN_P(delim)); + newlen = numelems*(implstr.len/i)-implstr.len; + smart_str_alloc((&implstr),newlen,0); } zend_hash_move_forward_ex(Z_ARRVAL_P(arr), &pos); } @@ -1924,6 +1928,10 @@ key = emalloc(maxlen+1); pos = 0; + { + size_t newlen; + smart_str_alloc((&result),slen,0); + } while (pos < slen) { if ((pos + maxlen) > slen) { @@ -2556,6 +2564,9 @@ char *r; char *end = haystack + length; smart_str result = {0}; + size_t newlen; //used by smart_str_alloc + + smart_str_alloc((&result),length,0); for (p = haystack; (r = php_memnstr(p, needle, needle_len, end)); --------------020604060900080400010702--