Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 115 lines (94 sloc) 3.253 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"
009025e * header file cleanup
Stig S. Bakken authored
23 #ifdef HAVE_STDARG_H
24 # include <stdarg.h>
e9e7bc6 @andigutmans - Add ptr_stack_n_{push,pop} in order to speed up function calls a bit.
andigutmans authored
25 #endif
573b460 @andigutmans Zend Library
andigutmans authored
26
27 ZEND_API void zend_ptr_stack_init(zend_ptr_stack *stack)
28 {
e9e7bc6 @andigutmans - Add ptr_stack_n_{push,pop} in order to speed up function calls a bit.
andigutmans authored
29 stack->top_element = stack->elements = (void **) emalloc(sizeof(void *)*PTR_STACK_BLOCK_SIZE);
30 stack->max = PTR_STACK_BLOCK_SIZE;
573b460 @andigutmans Zend Library
andigutmans authored
31 stack->top = 0;
32 }
33
34
35 ZEND_API inline void zend_ptr_stack_push(zend_ptr_stack *stack, void *ptr)
36 {
37 if (stack->top >= stack->max) { /* we need to allocate more memory */
38 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
39 stack->top_element = stack->elements+stack->top;
573b460 @andigutmans Zend Library
andigutmans authored
40 }
41 stack->top++;
42 *(stack->top_element++) = ptr;
43 }
44
e9e7bc6 @andigutmans - Add ptr_stack_n_{push,pop} in order to speed up function calls a bit.
andigutmans authored
45 ZEND_API inline void zend_ptr_stack_n_push(zend_ptr_stack *stack, int count,...)
46 {
47 va_list ptr;
48 void *elem;
49
50 if (stack->top+count > stack->max) { /* we need to allocate more memory */
51 stack->max *= 2;
52 stack->max += count;
53 stack->elements = (void **) erealloc(stack->elements, (sizeof(void *) * (stack->max)));
54 stack->top_element = stack->elements+stack->top;
55 }
56 va_start(ptr, count);
57 while (count>0) {
58 elem = va_arg(ptr, void *);
59 stack->top++;
60 *(stack->top_element++) = elem;
61 count--;
62 }
63 va_end(ptr);
64 }
65
66
67 ZEND_API inline void zend_ptr_stack_n_pop(zend_ptr_stack *stack, int count,...)
68 {
69 va_list ptr;
70 void **elem;
71
72 va_start(ptr, count);
73 while (count>0) {
74 elem = va_arg(ptr, void **);
447eb3b @andigutmans - Damn that's more like it.
andigutmans authored
75 *elem = *(--stack->top_element);
e9e7bc6 @andigutmans - Add ptr_stack_n_{push,pop} in order to speed up function calls a bit.
andigutmans authored
76 stack->top--;
77 count--;
78 }
79 va_end(ptr);
80 }
573b460 @andigutmans Zend Library
andigutmans authored
81
82 ZEND_API inline void *zend_ptr_stack_pop(zend_ptr_stack *stack)
83 {
84 stack->top--;
85 return *(--stack->top_element);
86 }
87
88
89 ZEND_API void zend_ptr_stack_destroy(zend_ptr_stack *stack)
90 {
91 if (stack->elements) {
92 efree(stack->elements);
93 }
94 }
95
96
97 ZEND_API void zend_ptr_stack_apply(zend_ptr_stack *stack, void (*func)(void *))
98 {
99 int i = stack->top;
100
101 while (--i >= 0) {
102 func(stack->elements[i]);
103 }
104 }
105
106
107 ZEND_API void zend_ptr_stack_clean(zend_ptr_stack *stack, void (*func)(void *))
108 {
109 zend_ptr_stack_apply(stack, func);
110 stack->top = 0;
3fcc651 @andigutmans * Optimize argument_stack top lookup
andigutmans authored
111 stack->top_element = stack->elements;
573b460 @andigutmans Zend Library
andigutmans authored
112 }
39a7f4c @zsuraski This patch is a go. Not fully optimized yet, but working properly.
zsuraski authored
113
114
Something went wrong with that request. Please try again.