Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 116 lines (94 sloc) 3.257 kb
573b460 @andigutmans Zend Library
andigutmans authored
1 /*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski |
6 +----------------------------------------------------------------------+
8d1de13 @zsuraski 0.91 update
zsuraski authored
7 | This source file is subject to version 0.91 of the Zend license, |
b5b1117 @zsuraski License update
zsuraski authored
8 | that is bundled with this package in the file LICENSE, and is |
9 | available at through the world-wide-web at |
8d1de13 @zsuraski 0.91 update
zsuraski authored
10 | http://www.zend.com/license/0_91.txt. |
b5b1117 @zsuraski License update
zsuraski authored
11 | If you did not receive a copy of the Zend license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@zend.com so we can mail you a copy immediately. |
573b460 @andigutmans Zend Library
andigutmans authored
14 +----------------------------------------------------------------------+
15 | Authors: Andi Gutmans <andi@zend.com> |
16 | Zeev Suraski <zeev@zend.com> |
17 +----------------------------------------------------------------------+
18 */
19
b5b1117 @zsuraski License update
zsuraski authored
20
573b460 @andigutmans Zend Library
andigutmans authored
21 #include "zend.h"
22 #include "zend_ptr_stack.h"
e9e7bc6 @andigutmans - Add ptr_stack_n_{push,pop} in order to speed up function calls a bit.
andigutmans authored
23 #if HAVE_STDARG_H
24 #include <stdarg.h>
25 #endif
573b460 @andigutmans Zend Library
andigutmans authored
26
27
28 ZEND_API void zend_ptr_stack_init(zend_ptr_stack *stack)
29 {
e9e7bc6 @andigutmans - Add ptr_stack_n_{push,pop} in order to speed up function calls a bit.
andigutmans authored
30 stack->top_element = stack->elements = (void **) emalloc(sizeof(void *)*PTR_STACK_BLOCK_SIZE);
31 stack->max = PTR_STACK_BLOCK_SIZE;
573b460 @andigutmans Zend Library
andigutmans authored
32 stack->top = 0;
33 }
34
35
36 ZEND_API inline void zend_ptr_stack_push(zend_ptr_stack *stack, void *ptr)
37 {
38 if (stack->top >= stack->max) { /* we need to allocate more memory */
39 stack->elements = (void **) erealloc(stack->elements, (sizeof(void *) * (stack->max *= 2 )));
e9e7bc6 @andigutmans - Add ptr_stack_n_{push,pop} in order to speed up function calls a bit.
andigutmans authored
40 stack->top_element = stack->elements+stack->top;
573b460 @andigutmans Zend Library
andigutmans authored
41 }
42 stack->top++;
43 *(stack->top_element++) = ptr;
44 }
45
e9e7bc6 @andigutmans - Add ptr_stack_n_{push,pop} in order to speed up function calls a bit.
andigutmans authored
46 ZEND_API inline void zend_ptr_stack_n_push(zend_ptr_stack *stack, int count,...)
47 {
48 va_list ptr;
49 void *elem;
50
51 if (stack->top+count > stack->max) { /* we need to allocate more memory */
52 stack->max *= 2;
53 stack->max += count;
54 stack->elements = (void **) erealloc(stack->elements, (sizeof(void *) * (stack->max)));
55 stack->top_element = stack->elements+stack->top;
56 }
57 va_start(ptr, count);
58 while (count>0) {
59 elem = va_arg(ptr, void *);
60 stack->top++;
61 *(stack->top_element++) = elem;
62 count--;
63 }
64 va_end(ptr);
65 }
66
67
68 ZEND_API inline void zend_ptr_stack_n_pop(zend_ptr_stack *stack, int count,...)
69 {
70 va_list ptr;
71 void **elem;
72
73 va_start(ptr, count);
74 while (count>0) {
75 elem = va_arg(ptr, void **);
76 *elem = *(stack->top_element--) = elem;
77 stack->top--;
78 count--;
79 }
80 va_end(ptr);
81 }
573b460 @andigutmans Zend Library
andigutmans authored
82
83 ZEND_API inline void *zend_ptr_stack_pop(zend_ptr_stack *stack)
84 {
85 stack->top--;
86 return *(--stack->top_element);
87 }
88
89
90 ZEND_API void zend_ptr_stack_destroy(zend_ptr_stack *stack)
91 {
92 if (stack->elements) {
93 efree(stack->elements);
94 }
95 }
96
97
98 ZEND_API void zend_ptr_stack_apply(zend_ptr_stack *stack, void (*func)(void *))
99 {
100 int i = stack->top;
101
102 while (--i >= 0) {
103 func(stack->elements[i]);
104 }
105 }
106
107
108 ZEND_API void zend_ptr_stack_clean(zend_ptr_stack *stack, void (*func)(void *))
109 {
110 zend_ptr_stack_apply(stack, func);
111 stack->top = 0;
3fcc651 @andigutmans * Optimize argument_stack top lookup
andigutmans authored
112 stack->top_element = stack->elements;
573b460 @andigutmans Zend Library
andigutmans authored
113 }
39a7f4c @zsuraski This patch is a go. Not fully optimized yet, but working properly.
zsuraski authored
114
115
Something went wrong with that request. Please try again.