]> granicus.if.org Git - php/commitdiff
zend_ptr_stack allocation is delayed before the actual usage
authorDmitry Stogov <dmitry@php.net>
Fri, 9 Jul 2010 07:31:18 +0000 (07:31 +0000)
committerDmitry Stogov <dmitry@php.net>
Fri, 9 Jul 2010 07:31:18 +0000 (07:31 +0000)
NEWS
Zend/zend_ptr_stack.c
Zend/zend_ptr_stack.h

diff --git a/NEWS b/NEWS
index 712366b66dfc4f8e1a4601908696068160c83130..000f8972e747fe7883dafb9c84d2df1d4f3f22aa 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -18,7 +18,7 @@ PHP                                                                        NEWS
     A constant class name may be used as a direct operand of ZEND_FETCH_*
     instruction without previous ZEND_FETCH_CLASS.
   . eliminated unnecessary iterations during request startup/shutdown
-  . zend_stack initialization is delayed before the actual usage
+  . zend_stack and zend_ptr_stack allocation is delayed before the actual usage
   . $GLOBALS became a JIT autoglobal, so it's initialized only if used
     (this may affect opcode caches)
 - Added concept of interned strings. All strings constants known at compile
index 0d4556d9ed28af997b311748ac213e9015ec0a54..af345987f7e95fda0c72011b0df6cfe49eecb6f3 100644 (file)
@@ -27,9 +27,8 @@
 
 ZEND_API void zend_ptr_stack_init_ex(zend_ptr_stack *stack, zend_bool persistent)
 {
-       stack->top_element = stack->elements = (void **) pemalloc(sizeof(void *)*PTR_STACK_BLOCK_SIZE, persistent);
-       stack->max = PTR_STACK_BLOCK_SIZE;
-       stack->top = 0;
+       stack->top_element = stack->elements = NULL;
+       stack->top = stack->max = 0;
        stack->persistent = persistent;
 }
 
index affe7d037bfae3e6349a4d65c72c5cc757eabb03..8f2828d54a8e195f9c7ca80c906115f316daeb13 100644 (file)
@@ -46,8 +46,9 @@ END_EXTERN_C()
 #define ZEND_PTR_STACK_RESIZE_IF_NEEDED(stack, count)          \
        if (stack->top+count > stack->max) {                                    \
                /* we need to allocate more memory */                           \
-               stack->max *= 2;                                                                        \
-               stack->max += count;                                                            \
+               do {                                                                                            \
+                       stack->max += PTR_STACK_BLOCK_SIZE;                             \
+               } while (stack->top+count > stack->max);                        \
                stack->elements = (void **) perealloc(stack->elements, (sizeof(void *) * (stack->max)), stack->persistent);     \
                stack->top_element = stack->elements+stack->top;        \
        }