Re: Smart strings & memory allocation
| From: | Stanislav Malyshev | Date: | Wed, 18 Jun 2003 13:01:52 +0000 |
| Subject: | Re: Smart strings & memory allocation | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-2361@lists.php.net to get a copy of this message | ||
SS>> If you move the additional check (newlen <
SS>> SMART_STR_START_SIZE) and preallocation into the if (!(d)->c)
SS>> branch, the changes won't affect the common code path.
IMO, the common code path is that of SMART_STR_START_SIZE, since as I
said 90% of strings never reach beyond initial alloc. But I see your
point, you are right, the START_SIZE one should be into if (!(d)->c)
branch.
SS>>
SS>> > @@ -47,7 +51,11 @@
SS>> > if (!(d)->c) (d)->len = (d)->a = 0; \
SS>> > newlen = (d)->len + (n); \
SS>> > if (newlen >= (d)->a) { \
SS>> > + if((d)->a == 0 && newlen < SMART_STR_START_SIZE) { \
SS>> > + (d)->a = SMART_STR_START_SIZE; \
SS>> > + } else { \
SS>> > (d)->a = newlen + SMART_STR_PREALLOC; \
SS>> > + } \
SS>> > (d)->c = SMART_STR_REALLOC((d)->c, (d)->a + 1, (what)); \
SS>> > } \
SS>> > } while (0)
SS>>
SS>> - Sascha
SS>>
SS>>
--
Stanislav Malyshev, Zend Products Engineer
stas@zend.com http://www.zend.com/ +972-3-6139665 ext.109