XCache is a fast, stable PHP opcode cacher that has been proven and is now running on production servers under high load. https://xcache.lighttpd.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.1 KiB

  1. #include <stdlib.h>
  2. #include "xc_trace.h"
  3. #include "xc_stack.h"
  4. typedef xc_stack_t* S;
  5. void xc_stack_init_ex(S stack, int initsize)
  6. {
  7. stack->cnt = 0;
  8. stack->size = initsize;
  9. stack->data = malloc(sizeof(void *) * stack->size);
  10. }
  11. void xc_stack_destroy(S stack)
  12. {
  13. free(stack->data);
  14. }
  15. void xc_stack_push(S stack, void *item)
  16. {
  17. if (stack->cnt == stack->size) {
  18. stack->size <<= 1;
  19. stack->data = realloc(stack->data, sizeof(void *) * stack->size);
  20. }
  21. stack->data[stack->cnt++] = item;
  22. }
  23. void* xc_stack_pop(S stack)
  24. {
  25. assert(stack != NULL);
  26. assert(stack->size > 0);
  27. return stack->data[--stack->cnt];
  28. }
  29. void* xc_stack_top(S stack)
  30. {
  31. assert(stack != NULL);
  32. assert(stack->cnt > 0);
  33. return stack->data[stack->cnt-1];
  34. }
  35. void* xc_stack_get(S stack, int n)
  36. {
  37. assert(stack != NULL);
  38. assert(stack->cnt > 0);
  39. return stack->data[n];
  40. }
  41. int xc_stack_count(S stack)
  42. {
  43. assert(stack != NULL);
  44. return stack->cnt;
  45. }
  46. void xc_stack_reverse(S stack)
  47. {
  48. int i, j;
  49. void *tmp;
  50. assert(stack != NULL);
  51. for (i = 0, j = stack->cnt - 1; i < j; i ++, j --) {
  52. tmp = stack->data[i];
  53. stack->data[i] = stack->data[j];
  54. stack->data[j] = tmp;
  55. }
  56. }