PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/opcache/Optimizer - zend_worklist.h (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 23 23 100.0 %
Date: 2019-04-07 Functions: 7 7 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2018 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andy Wingo <wingo@igalia.com>                               |
      16             :    +----------------------------------------------------------------------+
      17             : */
      18             : 
      19             : /* $Id:$ */
      20             : 
      21             : #ifndef _ZEND_WORKLIST_H_
      22             : #define _ZEND_WORKLIST_H_
      23             : 
      24             : #include "zend_arena.h"
      25             : #include "zend_bitset.h"
      26             : 
      27             : typedef struct _zend_worklist_stack {
      28             :         int *buf;
      29             :         int len;
      30             :         int capacity;
      31             : } zend_worklist_stack;
      32             : 
      33             : #define ZEND_WORKLIST_STACK_ALLOCA(s, _len, use_heap) do { \
      34             :                 (s)->buf = (int*)do_alloca(sizeof(int) * _len, use_heap); \
      35             :                 (s)->len = 0; \
      36             :                 (s)->capacity = _len; \
      37             :         } while (0)
      38             : 
      39             : #define ZEND_WORKLIST_STACK_FREE_ALLOCA(s, use_heap) \
      40             :         free_alloca((s)->buf, use_heap)
      41             : 
      42             : static inline int zend_worklist_stack_prepare(zend_arena **arena, zend_worklist_stack *stack, int len)
      43             : {
      44             :         ZEND_ASSERT(len >= 0);
      45             : 
      46             :         stack->buf = (int*)zend_arena_calloc(arena, sizeof(*stack->buf), len);
      47             :         if (!stack->buf) {
      48             :                 return FAILURE;
      49             :         }
      50             :         stack->len = 0;
      51             :         stack->capacity = len;
      52             : 
      53             :         return SUCCESS;
      54             : }
      55             : 
      56         901 : static inline void zend_worklist_stack_push(zend_worklist_stack *stack, int i)
      57             : {
      58         901 :         ZEND_ASSERT(stack->len < stack->capacity);
      59         901 :         stack->buf[stack->len++] = i;
      60         901 : }
      61             : 
      62        1205 : static inline int zend_worklist_stack_peek(zend_worklist_stack *stack)
      63             : {
      64        1205 :         ZEND_ASSERT(stack->len);
      65        1205 :         return stack->buf[stack->len - 1];
      66             : }
      67             : 
      68         901 : static inline int zend_worklist_stack_pop(zend_worklist_stack *stack)
      69             : {
      70         901 :         ZEND_ASSERT(stack->len);
      71         901 :         return stack->buf[--stack->len];
      72             : }
      73             : 
      74             : typedef struct _zend_worklist {
      75             :         zend_bitset visited;
      76             :         zend_worklist_stack stack;
      77             : } zend_worklist;
      78             : 
      79             : #define ZEND_WORKLIST_ALLOCA(w, _len, use_heap) do { \
      80             :                 (w)->stack.buf = (int*)do_alloca(ZEND_MM_ALIGNED_SIZE(sizeof(int) * _len) + sizeof(zend_ulong) * zend_bitset_len(_len), use_heap); \
      81             :                 (w)->stack.len = 0; \
      82             :                 (w)->stack.capacity = _len; \
      83             :                 (w)->visited = (zend_bitset)((char*)(w)->stack.buf + ZEND_MM_ALIGNED_SIZE(sizeof(int) * _len)); \
      84             :                 memset((w)->visited, 0, sizeof(zend_ulong) * zend_bitset_len(_len)); \
      85             :         } while (0)
      86             : 
      87             : #define ZEND_WORKLIST_FREE_ALLOCA(w, use_heap) \
      88             :         free_alloca((w)->stack.buf, use_heap)
      89             : 
      90             : static inline int zend_worklist_prepare(zend_arena **arena, zend_worklist *worklist, int len)
      91             : {
      92             :         ZEND_ASSERT(len >= 0);
      93             :         worklist->visited = (zend_bitset)zend_arena_calloc(arena, sizeof(zend_ulong), zend_bitset_len(len));
      94             :         if (!worklist->visited) {
      95             :                 return FAILURE;
      96             :         }
      97             :         return zend_worklist_stack_prepare(arena, &worklist->stack, len);
      98             : }
      99             : 
     100        2091 : static inline int zend_worklist_len(zend_worklist *worklist)
     101             : {
     102        2091 :         return worklist->stack.len;
     103             : }
     104             : 
     105        1456 : static inline int zend_worklist_push(zend_worklist *worklist, int i)
     106             : {
     107        1456 :         ZEND_ASSERT(i >= 0 && i < worklist->stack.capacity);
     108             : 
     109        1456 :         if (zend_bitset_in(worklist->visited, i)) {
     110         598 :                 return 0;
     111             :         }
     112             : 
     113         858 :         zend_bitset_incl(worklist->visited, i);
     114         858 :         zend_worklist_stack_push(&worklist->stack, i);
     115         858 :         return 1;
     116             : }
     117             : 
     118        1146 : static inline int zend_worklist_peek(zend_worklist *worklist)
     119             : {
     120        1146 :         return zend_worklist_stack_peek(&worklist->stack);
     121             : }
     122             : 
     123         858 : static inline int zend_worklist_pop(zend_worklist *worklist)
     124             : {
     125             :         /* Does not clear visited flag */
     126         858 :         return zend_worklist_stack_pop(&worklist->stack);
     127             : }
     128             : 
     129             : #endif /* _ZEND_WORKLIST_H_ */
     130             : 
     131             : /*
     132             :  * Local variables:
     133             :  * tab-width: 4
     134             :  * c-basic-offset: 4
     135             :  * indent-tabs-mode: t
     136             :  * End:
     137             :  */

Generated by: LCOV version 1.10

Generated at Sun, 07 Apr 2019 20:56:52 +0000 (11 days ago)

Copyright © 2005-2019 The PHP Group
All rights reserved.