Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:2360 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99490 invoked from network); 18 Jun 2003 12:57:18 -0000 Received: from unknown (HELO milton.schell.de) (217.160.72.35) by pb1.pair.com with SMTP; 18 Jun 2003 12:57:18 -0000 Received: (qmail 3230 invoked by uid 501); 18 Jun 2003 12:57:17 -0000 Received: from unknown (HELO eco.foo) (80.143.15.205) by kdserv.de with SMTP; 18 Jun 2003 12:57:17 -0000 Received: from localhost (localhost [127.0.0.1]) by eco.foo (Postfix) with ESMTP id 3B145514E2; Wed, 18 Jun 2003 14:57:17 +0200 (CEST) Date: Wed, 18 Jun 2003 14:57:17 +0200 (CEST) X-X-Sender: sas@eco.foo To: Stanislav Malyshev Cc: internals@lists.php.net In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: Re: [PHP-DEV] Smart strings & memory allocation From: sascha@schumann.cx (Sascha Schumann) Fine with the concept. If you move the additional check (newlen < SMART_STR_START_SIZE) and preallocation into the if (!(d)->c) branch, the changes won't affect the common code path. > @@ -47,7 +51,11 @@ > if (!(d)->c) (d)->len = (d)->a = 0; \ > newlen = (d)->len + (n); \ > if (newlen >= (d)->a) { \ > + if((d)->a == 0 && newlen < SMART_STR_START_SIZE) { \ > + (d)->a = SMART_STR_START_SIZE; \ > + } else { \ > (d)->a = newlen + SMART_STR_PREALLOC; \ > + } \ > (d)->c = SMART_STR_REALLOC((d)->c, (d)->a + 1, (what)); \ > } \ > } while (0) - Sascha