Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

- More ptr_stack optimizations and cleanups

  • Loading branch information...
commit d7c839d54f73c6649a13bc5f2178ec5a81ce930f 1 parent 138ef9a
authored July 30, 2004
4  Zend/zend_execute.c
@@ -2646,7 +2646,7 @@ int zend_do_fcall_common_helper(ZEND_OPCODE_HANDLER_ARGS)
2646 2646
 		NEXT_OPCODE(); /* Never reached */
2647 2647
 	}
2648 2648
 
2649  
-	zend_ptr_stack_n_push(&EG(argument_stack), 2, (void *) opline->extended_value, NULL);
  2649
+	zend_ptr_stack_2_push(&EG(argument_stack), (void *) opline->extended_value, NULL);
2650 2650
 
2651 2651
 	EX_T(opline->result.u.var).var.ptr_ptr = &EX_T(opline->result.u.var).var.ptr;
2652 2652
 
@@ -2790,7 +2790,7 @@ int zend_do_fcall_common_helper(ZEND_OPCODE_HANDLER_ARGS)
2790 2790
 		EG(This) = current_this;
2791 2791
 		EG(scope) = current_scope;
2792 2792
 	}
2793  
-	zend_ptr_stack_n_pop(&EG(arg_types_stack), 3, &EX(calling_scope), &EX(object), &EX(fbc));
  2793
+	zend_ptr_stack_3_pop(&EG(arg_types_stack), &EX(calling_scope), &EX(object), &EX(fbc));
2794 2794
 	
2795 2795
 	EX(function_state).function = (zend_function *) op_array;
2796 2796
 	EG(function_state_ptr) = &EX(function_state);
2  Zend/zend_execute_API.c
@@ -781,7 +781,7 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS
781 781
 		fci->param_count = 2;
782 782
 	}
783 783
 
784  
-	zend_ptr_stack_n_push(&EG(argument_stack), 2, (void *) (long) fci->param_count, NULL);
  784
+	zend_ptr_stack_2_push(&EG(argument_stack), (void *) (long) fci->param_count, NULL);
785 785
 
786 786
 	original_function_state_ptr = EG(function_state_ptr);
787 787
 	EG(function_state_ptr) = &EX(function_state);
8  Zend/zend_ptr_stack.c
@@ -38,12 +38,8 @@ ZEND_API void zend_ptr_stack_n_push(zend_ptr_stack *stack, int count, ...)
38 38
 	va_list ptr;
39 39
 	void *elem;
40 40
 	
41  
-	if (stack->top+count > stack->max) {		/* we need to allocate more memory */
42  
-		stack->max *= 2;
43  
-		stack->max += count; 
44  
-		stack->elements = (void **) erealloc(stack->elements, (sizeof(void *) * (stack->max)));
45  
-		stack->top_element = stack->elements+stack->top;
46  
-	}
  41
+	ZEND_PTR_STACK_RESIZE_IF_NEEDED(stack, count)
  42
+
47 43
 	va_start(ptr, count);
48 44
 	while (count>0) {
49 45
 		elem = va_arg(ptr, void *);
54  Zend/zend_ptr_stack.h
@@ -39,7 +39,16 @@ ZEND_API void zend_ptr_stack_destroy(zend_ptr_stack *stack);
39 39
 ZEND_API void zend_ptr_stack_apply(zend_ptr_stack *stack, void (*func)(void *));
40 40
 ZEND_API void zend_ptr_stack_clean(zend_ptr_stack *stack, void (*func)(void *), zend_bool free_elements);
41 41
 ZEND_API int zend_ptr_stack_num_elements(zend_ptr_stack *stack);
  42
+END_EXTERN_C()
42 43
 
  44
+#define ZEND_PTR_STACK_RESIZE_IF_NEEDED(stack, count)		\
  45
+	if (stack->top+count > stack->max) {					\
  46
+		/* we need to allocate more memory */				\
  47
+		stack->max *= 2;									\
  48
+		stack->max += count;								\
  49
+		stack->elements = (void **) erealloc(stack->elements, (sizeof(void *) * (stack->max)));	\
  50
+		stack->top_element = stack->elements+stack->top;	\
  51
+	}
43 52
 
44 53
 /*	Not doing this with a macro because of the loop unrolling in the element assignment.
45 54
 	Just using a macro for 3 in the body for readability sake. */
@@ -47,12 +56,7 @@ static inline void zend_ptr_stack_3_push(zend_ptr_stack *stack, void *a, void *b
47 56
 {
48 57
 #define ZEND_PTR_STACK_NUM_ARGS 3
49 58
 
50  
-	if (stack->top+ZEND_PTR_STACK_NUM_ARGS > stack->max) {		/* we need to allocate more memory */
51  
-		stack->max *= 2;
52  
-		stack->max += ZEND_PTR_STACK_NUM_ARGS; 
53  
-		stack->elements = (void **) erealloc(stack->elements, (sizeof(void *) * (stack->max)));
54  
-		stack->top_element = stack->elements+stack->top;
55  
-	}
  59
+	ZEND_PTR_STACK_RESIZE_IF_NEEDED(stack, ZEND_PTR_STACK_NUM_ARGS)
56 60
 
57 61
 	stack->top += ZEND_PTR_STACK_NUM_ARGS;
58 62
 	*(stack->top_element++) = a;
@@ -62,31 +66,31 @@ static inline void zend_ptr_stack_3_push(zend_ptr_stack *stack, void *a, void *b
62 66
 #undef ZEND_PTR_STACK_NUM_ARGS
63 67
 }
64 68
 
65  
-/*
66  
-ZEND_API void zend_ptr_stack_n_pop(zend_ptr_stack *stack, int count, ...)
  69
+static inline void zend_ptr_stack_2_push(zend_ptr_stack *stack, void *a, void *b)
67 70
 {
68  
-	va_list ptr;
69  
-	void **elem;
70  
-	
71  
-	va_start(ptr, count);
72  
-	while (count>0) {
73  
-		elem = va_arg(ptr, void **);
74  
-		*elem = *(--stack->top_element);
75  
-		stack->top--;
76  
-		count--;
77  
-	}
78  
-	va_end(ptr);
  71
+#define ZEND_PTR_STACK_NUM_ARGS 2
  72
+
  73
+	ZEND_PTR_STACK_RESIZE_IF_NEEDED(stack, ZEND_PTR_STACK_NUM_ARGS)
  74
+
  75
+	stack->top += ZEND_PTR_STACK_NUM_ARGS;
  76
+	*(stack->top_element++) = a;
  77
+	*(stack->top_element++) = b;
  78
+
  79
+#undef ZEND_PTR_STACK_NUM_ARGS
79 80
 }
80  
-*/
81 81
 
82  
-END_EXTERN_C()
  82
+static inline void zend_ptr_stack_3_pop(zend_ptr_stack *stack, void **a, void **b, void **c)
  83
+{
  84
+	*a = *(--stack->top_element);
  85
+	*b = *(--stack->top_element);
  86
+	*c = *(--stack->top_element);
  87
+	stack->top -= 3;;	
  88
+}
83 89
 
84 90
 static inline void zend_ptr_stack_push(zend_ptr_stack *stack, void *ptr)
85 91
 {
86  
-	if (stack->top >= stack->max) {		/* we need to allocate more memory */
87  
-		stack->elements = (void **) erealloc(stack->elements, (sizeof(void *) * (stack->max *= 2 )));
88  
-		stack->top_element = stack->elements+stack->top;
89  
-	}
  92
+	ZEND_PTR_STACK_RESIZE_IF_NEEDED(stack, 1)
  93
+
90 94
 	stack->top++;
91 95
 	*(stack->top_element++) = ptr;
92 96
 }

0 notes on commit d7c839d

Please sign in to comment.
Something went wrong with that request. Please try again.