Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions Zend/zend_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include "zend.h"
#include "zend_stack.h"

#define ZEND_STACK_ELEMENT(stack, n) ((void *)((char *) (stack)->elements + (stack)->size * (n)))

ZEND_API void zend_stack_init(zend_stack *stack, int size)
{
stack->size = size;
Expand All @@ -41,22 +39,6 @@ ZEND_API int zend_stack_push(zend_stack *stack, const void *element)
}


ZEND_API void *zend_stack_top(const zend_stack *stack)
{
if (stack->top > 0) {
return ZEND_STACK_ELEMENT(stack, stack->top - 1);
} else {
return NULL;
}
}


ZEND_API void zend_stack_del_top(zend_stack *stack)
{
--stack->top;
}


ZEND_API int zend_stack_int_top(const zend_stack *stack)
{
int *e = zend_stack_top(stack);
Expand All @@ -68,12 +50,6 @@ ZEND_API int zend_stack_int_top(const zend_stack *stack)
}


ZEND_API bool zend_stack_is_empty(const zend_stack *stack)
{
return stack->top == 0;
}


ZEND_API void zend_stack_destroy(zend_stack *stack)
{
if (stack->elements) {
Expand All @@ -83,18 +59,6 @@ ZEND_API void zend_stack_destroy(zend_stack *stack)
}


ZEND_API void *zend_stack_base(const zend_stack *stack)
{
return stack->elements;
}


ZEND_API int zend_stack_count(const zend_stack *stack)
{
return stack->top;
}


ZEND_API void zend_stack_apply(zend_stack *stack, int type, int (*apply_function)(void *element))
{
int i;
Expand Down
35 changes: 30 additions & 5 deletions Zend/zend_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ typedef struct _zend_stack {


#define STACK_BLOCK_SIZE 16
#define ZEND_STACK_ELEMENT(stack, n) ((void *)((char *) (stack)->elements + (stack)->size * (n)))

typedef enum {
ZEND_STACK_APPLY_TOPDOWN,
Expand All @@ -37,16 +38,40 @@ typedef enum {
BEGIN_EXTERN_C()
ZEND_API void zend_stack_init(zend_stack *stack, int size);
ZEND_API int zend_stack_push(zend_stack *stack, const void *element);
ZEND_API void *zend_stack_top(const zend_stack *stack);
ZEND_API void zend_stack_del_top(zend_stack *stack);
ZEND_API int zend_stack_int_top(const zend_stack *stack);
ZEND_API bool zend_stack_is_empty(const zend_stack *stack);
ZEND_API void zend_stack_destroy(zend_stack *stack);
ZEND_API void *zend_stack_base(const zend_stack *stack);
ZEND_API int zend_stack_count(const zend_stack *stack);
ZEND_API void zend_stack_apply(zend_stack *stack, int type, int (*apply_function)(void *element));
ZEND_API void zend_stack_apply_with_argument(zend_stack *stack, zend_stack_apply_direction type, int (*apply_function)(void *element, void *arg), void *arg);
ZEND_API void zend_stack_clean(zend_stack *stack, void (*func)(void *), bool free_elements);
END_EXTERN_C()

static zend_always_inline void *zend_stack_top(const zend_stack *stack)
{
if (stack->top > 0) {
return ZEND_STACK_ELEMENT(stack, stack->top - 1);
} else {
return NULL;
}
}

static zend_always_inline void zend_stack_del_top(zend_stack *stack)
{
--stack->top;
}

static zend_always_inline bool zend_stack_is_empty(const zend_stack *stack)
{
return stack->top == 0;
}

static zend_always_inline void *zend_stack_base(const zend_stack *stack)
{
return stack->elements;
}

static zend_always_inline int zend_stack_count(const zend_stack *stack)
{
return stack->top;
}

#endif /* ZEND_STACK_H */
2 changes: 1 addition & 1 deletion main/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ static inline void php_output_op(int op, const char *str, size_t len)

if (obh_cnt > 1) {
zend_stack_apply_with_argument(&OG(handlers), ZEND_STACK_APPLY_TOPDOWN, php_output_stack_apply_op, &context);
} else if ((active = zend_stack_top(&OG(handlers))) && (!((*active)->flags & PHP_OUTPUT_HANDLER_DISABLED))) {
} else if ((active = zend_stack_base(&OG(handlers))) && (!((*active)->flags & PHP_OUTPUT_HANDLER_DISABLED))) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this from top to base?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if above checks for handler count > 1, so this is the case where handler count = 1. So instead of going through return ZEND_STACK_ELEMENT(stack, stack->top - 1); we can just return stack->elements;.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good. You're right

php_output_handler_op(*active, &context);
} else {
php_output_context_pass(&context);
Expand Down
Loading