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 - Zend - zend_hash.h (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 101 106 95.3 %
Date: 2014-10-22 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2014 Zend Technologies Ltd. (http://www.zend.com) |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 2.00 of the Zend 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.zend.com/license/2_00.txt.                                |
      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.              |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andi Gutmans <andi@zend.com>                                |
      16             :    |          Zeev Suraski <zeev@zend.com>                                |
      17             :    +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #ifndef ZEND_HASH_H
      23             : #define ZEND_HASH_H
      24             : 
      25             : #include "zend.h"
      26             : 
      27             : #define HASH_KEY_IS_STRING 1
      28             : #define HASH_KEY_IS_LONG 2
      29             : #define HASH_KEY_NON_EXISTENT 3
      30             : 
      31             : #define HASH_UPDATE                     (1<<0)
      32             : #define HASH_ADD                                (1<<1)
      33             : #define HASH_UPDATE_INDIRECT    (1<<2)
      34             : #define HASH_ADD_NEW                    (1<<3)
      35             : #define HASH_ADD_NEXT                   (1<<4)
      36             : 
      37             : #define INVALID_IDX ((uint32_t) -1)
      38             : 
      39             : #define HASH_FLAG_PERSISTENT       (1<<0)
      40             : #define HASH_FLAG_APPLY_PROTECTION (1<<1)
      41             : #define HASH_FLAG_PACKED           (1<<2)
      42             : 
      43             : #define HASH_MASK_CONSISTENCY      0x60
      44             : 
      45             : typedef struct _zend_hash_key {
      46             :         zend_ulong h;
      47             :         zend_string *key;
      48             : } zend_hash_key;
      49             : 
      50             : typedef zend_bool (*merge_checker_func_t)(HashTable *target_ht, zval *source_data, zend_hash_key *hash_key, void *pParam);
      51             : 
      52             : typedef uint32_t HashPosition;
      53             : 
      54             : BEGIN_EXTERN_C()
      55             : 
      56             : /* startup/shutdown */
      57             : ZEND_API void _zend_hash_init(HashTable *ht, uint32_t nSize, dtor_func_t pDestructor, zend_bool persistent ZEND_FILE_LINE_DC);
      58             : ZEND_API void _zend_hash_init_ex(HashTable *ht, uint32_t nSize, dtor_func_t pDestructor, zend_bool persistent, zend_bool bApplyProtection ZEND_FILE_LINE_DC);
      59             : ZEND_API void zend_hash_destroy(HashTable *ht);
      60             : ZEND_API void zend_hash_clean(HashTable *ht);
      61             : #define zend_hash_init(ht, nSize, pHashFunction, pDestructor, persistent)                                               _zend_hash_init((ht), (nSize), (pDestructor), (persistent) ZEND_FILE_LINE_CC)
      62             : #define zend_hash_init_ex(ht, nSize, pHashFunction, pDestructor, persistent, bApplyProtection)          _zend_hash_init_ex((ht), (nSize), (pDestructor), (persistent), (bApplyProtection) ZEND_FILE_LINE_CC)
      63             : 
      64             : ZEND_API void zend_hash_real_init(HashTable *ht, zend_bool packed);
      65             : ZEND_API void zend_hash_packed_to_hash(HashTable *ht);
      66             : ZEND_API void zend_hash_to_packed(HashTable *ht);
      67             : 
      68             : /* additions/updates/changes */
      69             : ZEND_API zval *_zend_hash_add_or_update(HashTable *ht, zend_string *key, zval *pData, uint32_t flag ZEND_FILE_LINE_DC);
      70             : ZEND_API zval *_zend_hash_update(HashTable *ht, zend_string *key,zval *pData ZEND_FILE_LINE_DC);
      71             : ZEND_API zval *_zend_hash_update_ind(HashTable *ht, zend_string *key,zval *pData ZEND_FILE_LINE_DC);
      72             : ZEND_API zval *_zend_hash_add(HashTable *ht, zend_string *key,zval *pData ZEND_FILE_LINE_DC);
      73             : ZEND_API zval *_zend_hash_add_new(HashTable *ht, zend_string *key,zval *pData ZEND_FILE_LINE_DC);
      74             : 
      75             : #define zend_hash_update(ht, key, pData) \
      76             :                 _zend_hash_update(ht, key, pData ZEND_FILE_LINE_CC)
      77             : #define zend_hash_update_ind(ht, key, pData) \
      78             :                 _zend_hash_update_ind(ht, key, pData ZEND_FILE_LINE_CC)
      79             : #define zend_hash_add(ht, key, pData) \
      80             :                 _zend_hash_add(ht, key, pData ZEND_FILE_LINE_CC)
      81             : #define zend_hash_add_new(ht, key, pData) \
      82             :                 _zend_hash_add_new(ht, key, pData ZEND_FILE_LINE_CC)
      83             : 
      84             : ZEND_API zval *_zend_hash_str_add_or_update(HashTable *ht, const char *key, size_t len, zval *pData, uint32_t flag ZEND_FILE_LINE_DC);
      85             : ZEND_API zval *_zend_hash_str_update(HashTable *ht, const char *key, size_t len, zval *pData ZEND_FILE_LINE_DC);
      86             : ZEND_API zval *_zend_hash_str_update_ind(HashTable *ht, const char *key, size_t len, zval *pData ZEND_FILE_LINE_DC);
      87             : ZEND_API zval *_zend_hash_str_add(HashTable *ht, const char *key, size_t len, zval *pData ZEND_FILE_LINE_DC);
      88             : ZEND_API zval *_zend_hash_str_add_new(HashTable *ht, const char *key, size_t len, zval *pData ZEND_FILE_LINE_DC);
      89             : 
      90             : #define zend_hash_str_update(ht, key, len, pData) \
      91             :                 _zend_hash_str_update(ht, key, len, pData ZEND_FILE_LINE_CC)
      92             : #define zend_hash_str_update_ind(ht, key, len, pData) \
      93             :                 _zend_hash_str_update_ind(ht, key, len, pData ZEND_FILE_LINE_CC)
      94             : #define zend_hash_str_add(ht, key, len, pData) \
      95             :                 _zend_hash_str_add(ht, key, len, pData ZEND_FILE_LINE_CC)
      96             : #define zend_hash_str_add_new(ht, key, len, pData) \
      97             :                 _zend_hash_str_add_new(ht, key, len, pData ZEND_FILE_LINE_CC)
      98             : 
      99             : ZEND_API zval *_zend_hash_index_add_or_update(HashTable *ht, zend_ulong h, zval *pData, uint32_t flag ZEND_FILE_LINE_DC);
     100             : ZEND_API zval *_zend_hash_index_add(HashTable *ht, zend_ulong h, zval *pData ZEND_FILE_LINE_DC);
     101             : ZEND_API zval *_zend_hash_index_add_new(HashTable *ht, zend_ulong h, zval *pData ZEND_FILE_LINE_DC);
     102             : ZEND_API zval *_zend_hash_index_update(HashTable *ht, zend_ulong h, zval *pData ZEND_FILE_LINE_DC);
     103             : ZEND_API zval *_zend_hash_next_index_insert(HashTable *ht, zval *pData ZEND_FILE_LINE_DC);
     104             : ZEND_API zval *_zend_hash_next_index_insert_new(HashTable *ht, zval *pData ZEND_FILE_LINE_DC);
     105             : 
     106             : #define zend_hash_index_add(ht, h, pData) \
     107             :                 _zend_hash_index_add(ht, h, pData ZEND_FILE_LINE_CC)
     108             : #define zend_hash_index_add_new(ht, h, pData) \
     109             :                 _zend_hash_index_add_new(ht, h, pData ZEND_FILE_LINE_CC)
     110             : #define zend_hash_index_update(ht, h, pData) \
     111             :                 _zend_hash_index_update(ht, h, pData ZEND_FILE_LINE_CC)
     112             : #define zend_hash_next_index_insert(ht, pData) \
     113             :                 _zend_hash_next_index_insert(ht, pData ZEND_FILE_LINE_CC)
     114             : #define zend_hash_next_index_insert_new(ht, pData) \
     115             :                 _zend_hash_next_index_insert_new(ht, pData ZEND_FILE_LINE_CC)
     116             : 
     117             : ZEND_API zval *zend_hash_index_add_empty_element(HashTable *ht, zend_ulong h);
     118             : ZEND_API zval *zend_hash_add_empty_element(HashTable *ht, zend_string *key);
     119             : ZEND_API zval *zend_hash_str_add_empty_element(HashTable *ht, const char *key, size_t len);
     120             : 
     121             : #define ZEND_HASH_APPLY_KEEP                            0
     122             : #define ZEND_HASH_APPLY_REMOVE                          1<<0
     123             : #define ZEND_HASH_APPLY_STOP                            1<<1
     124             : 
     125             : typedef int (*apply_func_t)(zval *pDest TSRMLS_DC);
     126             : typedef int (*apply_func_arg_t)(zval *pDest, void *argument TSRMLS_DC);
     127             : typedef int (*apply_func_args_t)(zval *pDest TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key);
     128             : 
     129             : ZEND_API void zend_hash_graceful_destroy(HashTable *ht);
     130             : ZEND_API void zend_hash_graceful_reverse_destroy(HashTable *ht);
     131             : ZEND_API void zend_hash_apply(HashTable *ht, apply_func_t apply_func TSRMLS_DC);
     132             : ZEND_API void zend_hash_apply_with_argument(HashTable *ht, apply_func_arg_t apply_func, void * TSRMLS_DC);
     133             : ZEND_API void zend_hash_apply_with_arguments(HashTable *ht TSRMLS_DC, apply_func_args_t apply_func, int, ...);
     134             : 
     135             : /* This function should be used with special care (in other words,
     136             :  * it should usually not be used).  When used with the ZEND_HASH_APPLY_STOP
     137             :  * return value, it assumes things about the order of the elements in the hash.
     138             :  * Also, it does not provide the same kind of reentrancy protection that
     139             :  * the standard apply functions do.
     140             :  */
     141             : ZEND_API void zend_hash_reverse_apply(HashTable *ht, apply_func_t apply_func TSRMLS_DC);
     142             : 
     143             : 
     144             : /* Deletes */
     145             : ZEND_API int zend_hash_del(HashTable *ht, zend_string *key);
     146             : ZEND_API int zend_hash_del_ind(HashTable *ht, zend_string *key);
     147             : ZEND_API int zend_hash_str_del(HashTable *ht, const char *key, size_t len);
     148             : ZEND_API int zend_hash_str_del_ind(HashTable *ht, const char *key, size_t len);
     149             : ZEND_API int zend_hash_index_del(HashTable *ht, zend_ulong h);
     150             : 
     151             : /* Data retreival */
     152             : ZEND_API zval *zend_hash_find(const HashTable *ht, zend_string *key);
     153             : ZEND_API zval *zend_hash_str_find(const HashTable *ht, const char *key, size_t len);
     154             : ZEND_API zval *zend_hash_index_find(const HashTable *ht, zend_ulong h);
     155             : 
     156             : /* Misc */
     157             : ZEND_API zend_bool zend_hash_exists(const HashTable *ht, zend_string *key);
     158             : ZEND_API zend_bool zend_hash_str_exists(const HashTable *ht, const char *str, size_t len);
     159             : ZEND_API zend_bool zend_hash_index_exists(const HashTable *ht, zend_ulong h);
     160             : 
     161             : /* traversing */
     162             : #define zend_hash_has_more_elements_ex(ht, pos) \
     163             :         (zend_hash_get_current_key_type_ex(ht, pos) == HASH_KEY_NON_EXISTENT ? FAILURE : SUCCESS)
     164             : ZEND_API int zend_hash_move_forward_ex(HashTable *ht, HashPosition *pos);
     165             : ZEND_API int zend_hash_move_backwards_ex(HashTable *ht, HashPosition *pos);
     166             : ZEND_API int zend_hash_get_current_key_ex(const HashTable *ht, zend_string **str_index, zend_ulong *num_index, zend_bool duplicate, HashPosition *pos);
     167             : ZEND_API void zend_hash_get_current_key_zval_ex(const HashTable *ht, zval *key, HashPosition *pos);
     168             : ZEND_API int zend_hash_get_current_key_type_ex(HashTable *ht, HashPosition *pos);
     169             : ZEND_API zval *zend_hash_get_current_data_ex(HashTable *ht, HashPosition *pos);
     170             : ZEND_API void zend_hash_internal_pointer_reset_ex(HashTable *ht, HashPosition *pos);
     171             : ZEND_API void zend_hash_internal_pointer_end_ex(HashTable *ht, HashPosition *pos);
     172             : 
     173             : typedef struct _HashPointer {
     174             :         HashPosition  pos;
     175             :         HashTable    *ht;
     176             :         zend_ulong    h;
     177             :         zend_string  *key;
     178             : } HashPointer;
     179             : 
     180             : #define zend_hash_has_more_elements(ht) \
     181             :         zend_hash_has_more_elements_ex(ht, &(ht)->nInternalPointer)
     182             : #define zend_hash_move_forward(ht) \
     183             :         zend_hash_move_forward_ex(ht, &(ht)->nInternalPointer)
     184             : #define zend_hash_move_backwards(ht) \
     185             :         zend_hash_move_backwards_ex(ht, &(ht)->nInternalPointer)
     186             : #define zend_hash_get_current_key(ht, str_index, num_index, duplicate) \
     187             :         zend_hash_get_current_key_ex(ht, str_index, num_index, duplicate, &(ht)->nInternalPointer)
     188             : #define zend_hash_get_current_key_zval(ht, key) \
     189             :         zend_hash_get_current_key_zval_ex(ht, key, &(ht)->nInternalPointer)
     190             : #define zend_hash_get_current_key_type(ht) \
     191             :         zend_hash_get_current_key_type_ex(ht, &(ht)->nInternalPointer)
     192             : #define zend_hash_get_current_data(ht) \
     193             :         zend_hash_get_current_data_ex(ht, &(ht)->nInternalPointer)
     194             : #define zend_hash_internal_pointer_reset(ht) \
     195             :         zend_hash_internal_pointer_reset_ex(ht, &(ht)->nInternalPointer)
     196             : #define zend_hash_internal_pointer_end(ht) \
     197             :         zend_hash_internal_pointer_end_ex(ht, &(ht)->nInternalPointer)
     198             : 
     199             : /* Copying, merging and sorting */
     200             : ZEND_API void zend_hash_copy(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor);
     201             : ZEND_API void _zend_hash_merge(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, zend_bool overwrite ZEND_FILE_LINE_DC);
     202             : ZEND_API void zend_hash_merge_ex(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, merge_checker_func_t pMergeSource, void *pParam);
     203             : ZEND_API int zend_hash_sort(HashTable *ht, sort_func_t sort_func, compare_func_t compare_func, zend_bool renumber TSRMLS_DC);
     204             : ZEND_API int zend_hash_compare(HashTable *ht1, HashTable *ht2, compare_func_t compar, zend_bool ordered TSRMLS_DC);
     205             : ZEND_API zval *zend_hash_minmax(const HashTable *ht, compare_func_t compar, uint32_t flag TSRMLS_DC);
     206             : 
     207             : #define zend_hash_merge(target, source, pCopyConstructor, overwrite)                                    \
     208             :         _zend_hash_merge(target, source, pCopyConstructor, overwrite ZEND_FILE_LINE_CC)
     209             : 
     210             : #define zend_hash_num_elements(ht) \
     211             :         (ht)->nNumOfElements
     212             : 
     213             : #define zend_hash_next_free_element(ht) \
     214             :         (ht)->nNextFreeElement
     215             : 
     216             : ZEND_API int zend_hash_rehash(HashTable *ht);
     217             : 
     218             : ZEND_API void zend_array_dup(HashTable *target, HashTable *source);
     219             : 
     220             : #if ZEND_DEBUG
     221             : /* debug */
     222             : void zend_hash_display_pListTail(const HashTable *ht);
     223             : void zend_hash_display(const HashTable *ht);
     224             : #endif
     225             : 
     226             : ZEND_API int _zend_handle_numeric_str_ex(const char *key, size_t length, zend_ulong *idx);
     227             : 
     228             : END_EXTERN_C()
     229             : 
     230             : #define ZEND_INIT_SYMTABLE(ht)                                                          \
     231             :         ZEND_INIT_SYMTABLE_EX(ht, 8, 0)
     232             : 
     233             : #define ZEND_INIT_SYMTABLE_EX(ht, n, persistent)                        \
     234             :         zend_hash_init(ht, n, NULL, ZVAL_PTR_DTOR, persistent)
     235             : 
     236             : static zend_always_inline int _zend_handle_numeric_str(const char *key, size_t length, zend_ulong *idx)
     237             : {
     238     5005560 :         register const char *tmp = key;
     239             : 
     240     5005560 :         if (*tmp > '9') {
     241     4587567 :                 return 0;
     242      417993 :         } else if (*tmp < '0') {
     243       35610 :                 if (*tmp != '-') {
     244       35529 :                         return 0;
     245             :                 }
     246          81 :                 tmp++;
     247          81 :                 if (*tmp > '9' || *tmp < '0') {
     248          22 :                         return 0;
     249             :                 }
     250             :         }
     251      382442 :         return _zend_handle_numeric_str_ex(key, length, idx);
     252             : }
     253             : 
     254             : #define ZEND_HANDLE_NUMERIC_STR(key, length, idx) \
     255             :         _zend_handle_numeric_str(key, length, &idx)
     256             : 
     257             : #define ZEND_HANDLE_NUMERIC(key, idx) \
     258             :         ZEND_HANDLE_NUMERIC_STR((key)->val, (key)->len, idx)
     259             : 
     260             : 
     261             : static zend_always_inline zval *zend_hash_find_ind(const HashTable *ht, zend_string *key)
     262             : {
     263             :         zval *zv;
     264             : 
     265      268729 :         zv = zend_hash_find(ht, key);
     266      297992 :         return (zv && Z_TYPE_P(zv) == IS_INDIRECT) ? Z_INDIRECT_P(zv) : zv;
     267             : }
     268             : 
     269             : 
     270             : static zend_always_inline int zend_hash_exists_ind(const HashTable *ht, zend_string *key)
     271             : {
     272             :         zval *zv;
     273             : 
     274         219 :         zv = zend_hash_find(ht, key);
     275         378 :         return zv && (Z_TYPE_P(zv) != IS_INDIRECT ||
     276          27 :                         Z_TYPE_P(Z_INDIRECT_P(zv)) != IS_UNDEF);
     277             : }
     278             : 
     279             : 
     280             : static zend_always_inline zval *zend_hash_str_find_ind(const HashTable *ht, const char *str, size_t len)
     281             : {
     282             :         zval *zv;
     283             : 
     284         738 :         zv = zend_hash_str_find(ht, str, len);
     285        1473 :         return (zv && Z_TYPE_P(zv) == IS_INDIRECT) ? Z_INDIRECT_P(zv) : zv;
     286             : }
     287             : 
     288             : 
     289             : static zend_always_inline zval *zend_symtable_update(HashTable *ht, zend_string *key, zval *pData)
     290             : {
     291             :         zend_ulong idx;
     292             : 
     293       38188 :         if (ZEND_HANDLE_NUMERIC(key, idx)) {
     294         326 :                 return zend_hash_index_update(ht, idx, pData);
     295             :         } else {
     296       18768 :                 return zend_hash_update(ht, key, pData);
     297             :         }
     298             : }
     299             : 
     300             : 
     301             : static zend_always_inline zval *zend_symtable_update_ind(HashTable *ht, zend_string *key, zval *pData)
     302             : {
     303             :         zend_ulong idx;
     304             : 
     305         116 :         if (ZEND_HANDLE_NUMERIC(key, idx)) {
     306           1 :                 return zend_hash_index_update(ht, idx, pData);
     307             :         } else {
     308          57 :                 return zend_hash_update_ind(ht, key, pData);
     309             :         }
     310             : }
     311             : 
     312             : 
     313             : static zend_always_inline int zend_symtable_del(HashTable *ht, zend_string *key)
     314             : {
     315             :         zend_ulong idx;
     316             : 
     317          32 :         if (ZEND_HANDLE_NUMERIC(key, idx)) {
     318           6 :                 return zend_hash_index_del(ht, idx);
     319             :         } else {
     320          10 :                 return zend_hash_del(ht, key);
     321             :         }
     322             : }
     323             : 
     324             : 
     325             : static zend_always_inline int zend_symtable_del_ind(HashTable *ht, zend_string *key)
     326             : {
     327             :         zend_ulong idx;
     328             : 
     329             :         if (ZEND_HANDLE_NUMERIC(key, idx)) {
     330             :                 return zend_hash_index_del(ht, idx);
     331             :         } else {
     332             :                 return zend_hash_del_ind(ht, key);
     333             :         }
     334             : }
     335             : 
     336             : 
     337             : static zend_always_inline zval *zend_symtable_find(const HashTable *ht, zend_string *key)
     338             : {
     339             :         zend_ulong idx;
     340             : 
     341        1540 :         if (ZEND_HANDLE_NUMERIC(key, idx)) {
     342          28 :                 return zend_hash_index_find(ht, idx);
     343             :         } else {
     344         742 :                 return zend_hash_find(ht, key);
     345             :         }
     346             : }
     347             : 
     348             : 
     349             : static zend_always_inline zval *zend_symtable_find_ind(const HashTable *ht, zend_string *key)
     350             : {
     351             :         zend_ulong idx;
     352             : 
     353             :         if (ZEND_HANDLE_NUMERIC(key, idx)) {
     354             :                 return zend_hash_index_find(ht, idx);
     355             :         } else {
     356             :                 return zend_hash_find_ind(ht, key);
     357             :         }
     358             : }
     359             : 
     360             : 
     361             : static zend_always_inline int zend_symtable_exists(HashTable *ht, zend_string *key)
     362             : {
     363             :         zend_ulong idx;
     364             : 
     365      277022 :         if (ZEND_HANDLE_NUMERIC(key, idx)) {
     366          20 :                 return zend_hash_index_exists(ht, idx);
     367             :         } else {
     368      138491 :                 return zend_hash_exists(ht, key);
     369             :         }
     370             : }
     371             : 
     372             : 
     373             : static zend_always_inline zval *zend_symtable_str_update(HashTable *ht, const char *str, size_t len, zval *pData)
     374             : {
     375             :         zend_ulong idx;
     376             : 
     377      312849 :         if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
     378        1170 :                 return zend_hash_index_update(ht, idx, pData);
     379             :         } else {
     380      311679 :                 return zend_hash_str_update(ht, str, len, pData);
     381             :         }
     382             : }
     383             : 
     384             : 
     385             : static zend_always_inline zval *zend_symtable_str_update_ind(HashTable *ht, const char *str, size_t len, zval *pData)
     386             : {
     387             :         zend_ulong idx;
     388             : 
     389     1236193 :         if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
     390          28 :                 return zend_hash_index_update(ht, idx, pData);
     391             :         } else {
     392     1236165 :                 return zend_hash_str_update_ind(ht, str, len, pData);
     393             :         }
     394             : }
     395             : 
     396             : 
     397             : static zend_always_inline int zend_symtable_str_del(HashTable *ht, const char *str, size_t len)
     398             : {
     399             :         zend_ulong idx;
     400             : 
     401           8 :         if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
     402           2 :                 return zend_hash_index_del(ht, idx);
     403             :         } else {
     404           6 :                 return zend_hash_str_del(ht, str, len);
     405             :         }
     406             : }
     407             : 
     408             : 
     409             : static zend_always_inline int zend_symtable_str_del_ind(HashTable *ht, const char *str, size_t len)
     410             : {
     411             :         zend_ulong idx;
     412             : 
     413             :         if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
     414             :                 return zend_hash_index_del(ht, idx);
     415             :         } else {
     416             :                 return zend_hash_str_del_ind(ht, str, len);
     417             :         }
     418             : }
     419             : 
     420             : 
     421             : static zend_always_inline zval *zend_symtable_str_find(HashTable *ht, const char *str, size_t len)
     422             : {
     423             :         zend_ulong idx;
     424             : 
     425         434 :         if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
     426          23 :                 return zend_hash_index_find(ht, idx);
     427             :         } else {
     428         411 :                 return zend_hash_str_find(ht, str, len);
     429             :         }
     430             : }
     431             : 
     432             : 
     433             : static zend_always_inline int zend_symtable_str_exists(HashTable *ht, const char *str, size_t len)
     434             : {
     435             :         zend_ulong idx;
     436             : 
     437          75 :         if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
     438           0 :                 return zend_hash_index_exists(ht, idx);
     439             :         } else {
     440          75 :                 return zend_hash_str_exists(ht, str, len);
     441             :         }
     442             : }
     443             : 
     444             : static zend_always_inline void *zend_hash_add_ptr(HashTable *ht, zend_string *key, void *pData)
     445             : {
     446             :         zval tmp, *zv;
     447             : 
     448   133365256 :         ZVAL_PTR(&tmp, pData);
     449   133365256 :         zv = zend_hash_add(ht, key, &tmp);
     450   133365256 :         return zv ? Z_PTR_P(zv) : NULL;
     451             : }
     452             : 
     453             : static zend_always_inline void *zend_hash_add_new_ptr(HashTable *ht, zend_string *key, void *pData)
     454             : {
     455             :         zval tmp, *zv;
     456             : 
     457    27085991 :         ZVAL_PTR(&tmp, pData);
     458    27085991 :         zv = zend_hash_add_new(ht, key, &tmp);
     459    27085991 :         return zv ? Z_PTR_P(zv) : NULL;
     460             : }
     461             : 
     462             : static zend_always_inline void *zend_hash_str_add_ptr(HashTable *ht, const char *str, size_t len, void *pData)
     463             : {
     464             :         zval tmp, *zv;
     465             : 
     466     8691137 :         ZVAL_PTR(&tmp, pData);
     467     8691137 :         zv = zend_hash_str_add(ht, str, len, &tmp);
     468     8691137 :         return zv ? Z_PTR_P(zv) : NULL;
     469             : }
     470             : 
     471             : static zend_always_inline void *zend_hash_update_ptr(HashTable *ht, zend_string *key, void *pData)
     472             : {
     473             :         zval tmp, *zv;
     474             : 
     475    51757546 :         ZVAL_PTR(&tmp, pData);
     476    51757546 :         zv = zend_hash_update(ht, key, &tmp);
     477    51757546 :         return zv ? Z_PTR_P(zv) : NULL;
     478             : }
     479             : 
     480             : static zend_always_inline void *zend_hash_str_update_ptr(HashTable *ht, const char *str, size_t len, void *pData)
     481             : {
     482             :         zval tmp, *zv;
     483             : 
     484      985674 :         ZVAL_PTR(&tmp, pData);
     485      985674 :         zv = zend_hash_str_update(ht, str, len, &tmp);
     486      985674 :         return zv ? Z_PTR_P(zv) : NULL;
     487             : }
     488             : 
     489             : static zend_always_inline void *zend_hash_add_mem(HashTable *ht, zend_string *key, void *pData, size_t size)
     490             : {
     491             :         zval tmp, *zv;
     492             : 
     493     2573639 :         ZVAL_PTR(&tmp, NULL);
     494     2573639 :         if ((zv = zend_hash_add(ht, key, &tmp))) {
     495     5147274 :                 Z_PTR_P(zv) = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
     496     2573637 :                 memcpy(Z_PTR_P(zv), pData, size);
     497     2573637 :                 return Z_PTR_P(zv);
     498             :         }
     499           2 :         return NULL;
     500             : }
     501             : 
     502             : static zend_always_inline void *zend_hash_str_add_mem(HashTable *ht, const char *str, size_t len, void *pData, size_t size)
     503             : {
     504             :         zval tmp, *zv;
     505             : 
     506     3355813 :         ZVAL_PTR(&tmp, NULL);
     507     3355813 :         if ((zv = zend_hash_str_add(ht, str, len, &tmp))) {
     508     6670746 :                 Z_PTR_P(zv) = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
     509     3335373 :                 memcpy(Z_PTR_P(zv), pData, size);
     510     3335373 :                 return Z_PTR_P(zv);
     511             :         }
     512       20440 :         return NULL;
     513             : }
     514             : 
     515             : static zend_always_inline void *zend_hash_update_mem(HashTable *ht, zend_string *key, void *pData, size_t size)
     516             : {
     517             :         void *p;
     518             : 
     519    90445626 :         p = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
     520    45222813 :         memcpy(p, pData, size);
     521    45222813 :         return zend_hash_update_ptr(ht, key, p);
     522             : }
     523             : 
     524             : static zend_always_inline void *zend_hash_str_update_mem(HashTable *ht, const char *str, size_t len, void *pData, size_t size)
     525             : {
     526             :         void *p;
     527             : 
     528       50498 :         p = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
     529       25249 :         memcpy(p, pData, size);
     530       25249 :         return zend_hash_str_update_ptr(ht, str, len, p);
     531             : }
     532             : 
     533             : static zend_always_inline void *zend_hash_index_update_ptr(HashTable *ht, zend_ulong h, void *pData)
     534             : {
     535             :         zval tmp, *zv;
     536             : 
     537     1268568 :         ZVAL_PTR(&tmp, pData);
     538     1268568 :         zv = zend_hash_index_update(ht, h, &tmp);
     539     1268568 :         return zv ? Z_PTR_P(zv) : NULL;
     540             : }
     541             : 
     542             : static zend_always_inline void *zend_hash_next_index_insert_ptr(HashTable *ht, void *pData)
     543             : {
     544             :         zval tmp, *zv;
     545             : 
     546       38999 :         ZVAL_PTR(&tmp, pData);
     547       38999 :         zv = zend_hash_next_index_insert(ht, &tmp);
     548       38999 :         return zv ? Z_PTR_P(zv) : NULL;
     549             : }
     550             : 
     551             : static zend_always_inline void *zend_hash_index_update_mem(HashTable *ht, zend_ulong h, void *pData, size_t size)
     552             : {
     553             :         void *p;
     554             : 
     555       13244 :         p = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
     556        6622 :         memcpy(p, pData, size);
     557        6622 :         return zend_hash_index_update_ptr(ht, h, p);
     558             : }
     559             : 
     560             : static zend_always_inline void *zend_hash_next_index_insert_mem(HashTable *ht, void *pData, size_t size)
     561             : {
     562             :         zval tmp, *zv;
     563             : 
     564         104 :         ZVAL_PTR(&tmp, NULL);
     565         104 :         if ((zv = zend_hash_next_index_insert(ht, &tmp))) {
     566         208 :                 Z_PTR_P(zv) = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
     567         104 :                 memcpy(Z_PTR_P(zv), pData, size);
     568         104 :                 return Z_PTR_P(zv);
     569             :         }
     570           0 :         return NULL;
     571             : }
     572             : 
     573             : static zend_always_inline void *zend_hash_find_ptr(const HashTable *ht, zend_string *key)
     574             : {
     575             :         zval *zv;
     576             : 
     577    41048508 :         zv = zend_hash_find(ht, key);
     578    41048508 :         return zv ? Z_PTR_P(zv) : NULL;
     579             : }
     580             : 
     581             : static zend_always_inline void *zend_hash_str_find_ptr(const HashTable *ht, const char *str, size_t len)
     582             : {
     583             :         zval *zv;
     584             : 
     585     1972757 :         zv = zend_hash_str_find(ht, str, len);
     586     1972757 :         return zv ? Z_PTR_P(zv) : NULL;
     587             : }
     588             : 
     589             : static zend_always_inline void *zend_hash_index_find_ptr(const HashTable *ht, zend_ulong h)
     590             : {
     591             :         zval *zv;
     592             : 
     593      257797 :         zv = zend_hash_index_find(ht, h);
     594      257797 :         return zv ? Z_PTR_P(zv) : NULL;
     595             : }
     596             : 
     597             : static zend_always_inline void *zend_symtable_str_find_ptr(HashTable *ht, const char *str, size_t len)
     598             : {
     599             :         zend_ulong idx;
     600             : 
     601           0 :         if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
     602           0 :                 return zend_hash_index_find_ptr(ht, idx);
     603             :         } else {
     604           0 :                 return zend_hash_str_find_ptr(ht, str, len);
     605             :         }
     606             : }
     607             : 
     608             : static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, HashPosition *pos)
     609             : {
     610             :         zval *zv;
     611             : 
     612       64298 :         zv = zend_hash_get_current_data_ex(ht, pos);
     613       64298 :         return zv ? Z_PTR_P(zv) : NULL;
     614             : }
     615             : 
     616             : #define zend_hash_get_current_data_ptr(ht) \
     617             :         zend_hash_get_current_data_ptr_ex(ht, &(ht)->nInternalPointer)
     618             : 
     619             : #define ZEND_HASH_FOREACH(_ht, indirect) do { \
     620             :                 uint _idx; \
     621             :                 for (_idx = 0; _idx < (_ht)->nNumUsed; _idx++) { \
     622             :                         Bucket *_p = (_ht)->arData + _idx; \
     623             :                         zval *_z = &_p->val; \
     624             :                         if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \
     625             :                                 _z = Z_INDIRECT_P(_z); \
     626             :                         } \
     627             :                         if (Z_TYPE_P(_z) == IS_UNDEF) continue;
     628             : 
     629             : #define ZEND_HASH_REVERSE_FOREACH(_ht, indirect) do { \
     630             :                 uint _idx; \
     631             :                 for (_idx = (_ht)->nNumUsed; _idx > 0; _idx--) { \
     632             :                         Bucket *_p = (_ht)->arData + _idx - 1; \
     633             :                         zval *_z = &_p->val; \
     634             :                         if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \
     635             :                                 _z = Z_INDIRECT_P(_z); \
     636             :                         } \
     637             :                         if (Z_TYPE_P(_z) == IS_UNDEF) continue;
     638             : 
     639             : #define ZEND_HASH_FOREACH_END() \
     640             :                 } \
     641             :         } while (0)
     642             :         
     643             : #define ZEND_HASH_FOREACH_BUCKET(ht, _bucket) \
     644             :         ZEND_HASH_FOREACH(ht, 0); \
     645             :         _bucket = _p;
     646             : 
     647             : #define ZEND_HASH_FOREACH_VAL(ht, _val) \
     648             :         ZEND_HASH_FOREACH(ht, 0); \
     649             :         _val = _z;
     650             : 
     651             : #define ZEND_HASH_FOREACH_VAL_IND(ht, _val) \
     652             :         ZEND_HASH_FOREACH(ht, 1); \
     653             :         _val = _z;
     654             : 
     655             : #define ZEND_HASH_FOREACH_PTR(ht, _ptr) \
     656             :         ZEND_HASH_FOREACH(ht, 0); \
     657             :         _ptr = Z_PTR_P(_z);
     658             : 
     659             : #define ZEND_HASH_FOREACH_NUM_KEY(ht, _h) \
     660             :         ZEND_HASH_FOREACH(ht, 0); \
     661             :         _h = _p->h;
     662             : 
     663             : #define ZEND_HASH_FOREACH_STR_KEY(ht, _key) \
     664             :         ZEND_HASH_FOREACH(ht, 0); \
     665             :         _key = _p->key;
     666             :                 
     667             : #define ZEND_HASH_FOREACH_KEY(ht, _h, _key) \
     668             :         ZEND_HASH_FOREACH(ht, 0); \
     669             :         _h = _p->h; \
     670             :         _key = _p->key;
     671             : 
     672             : #define ZEND_HASH_FOREACH_NUM_KEY_VAL(ht, _h, _val) \
     673             :         ZEND_HASH_FOREACH(ht, 0); \
     674             :         _h = _p->h; \
     675             :         _val = _z;
     676             :                 
     677             : #define ZEND_HASH_FOREACH_STR_KEY_VAL(ht, _key, _val) \
     678             :         ZEND_HASH_FOREACH(ht, 0); \
     679             :         _key = _p->key; \
     680             :         _val = _z;
     681             : 
     682             : #define ZEND_HASH_FOREACH_KEY_VAL(ht, _h, _key, _val) \
     683             :         ZEND_HASH_FOREACH(ht, 0); \
     684             :         _h = _p->h; \
     685             :         _key = _p->key; \
     686             :         _val = _z;
     687             : 
     688             : #define ZEND_HASH_FOREACH_STR_KEY_VAL_IND(ht, _key, _val) \
     689             :         ZEND_HASH_FOREACH(ht, 1); \
     690             :         _key = _p->key; \
     691             :         _val = _z;
     692             : 
     693             : #define ZEND_HASH_FOREACH_KEY_VAL_IND(ht, _h, _key, _val) \
     694             :         ZEND_HASH_FOREACH(ht, 1); \
     695             :         _h = _p->h; \
     696             :         _key = _p->key; \
     697             :         _val = _z;
     698             : 
     699             : #define ZEND_HASH_FOREACH_STR_KEY_PTR(ht, _key, _ptr) \
     700             :         ZEND_HASH_FOREACH(ht, 0); \
     701             :         _key = _p->key; \
     702             :         _ptr = Z_PTR_P(_z);
     703             : 
     704             : #define ZEND_HASH_FOREACH_KEY_PTR(ht, _h, _key, _ptr) \
     705             :         ZEND_HASH_FOREACH(ht, 0); \
     706             :         _h = _p->h; \
     707             :         _key = _p->key; \
     708             :         _ptr = Z_PTR_P(_z);
     709             : 
     710             : #define ZEND_HASH_REVERSE_FOREACH_VAL(ht, _val) \
     711             :         ZEND_HASH_REVERSE_FOREACH(ht, 0); \
     712             :         _val = _z;
     713             : 
     714             : #define ZEND_HASH_REVERSE_FOREACH_PTR(ht, _ptr) \
     715             :         ZEND_HASH_REVERSE_FOREACH(ht, 0); \
     716             :         _ptr = Z_PTR_P(_z);
     717             : 
     718             : #define ZEND_HASH_REVERSE_FOREACH_VAL_IND(ht, _val) \
     719             :         ZEND_HASH_REVERSE_FOREACH(ht, 1); \
     720             :         _val = _z;
     721             : 
     722             : #define ZEND_HASH_REVERSE_FOREACH_KEY_VAL(ht, _h, _key, _val) \
     723             :         ZEND_HASH_REVERSE_FOREACH(ht, 0); \
     724             :         _h = _p->h; \
     725             :         _key = _p->key; \
     726             :         _val = _z;
     727             : 
     728             : #define ZEND_HASH_REVERSE_FOREACH_KEY_VAL_IND(ht, _h, _key, _val) \
     729             :         ZEND_HASH_REVERSE_FOREACH(ht, 1); \
     730             :         _h = _p->h; \
     731             :         _key = _p->key; \
     732             :         _val = _z;
     733             : 
     734             : #define ZEND_HASH_APPLY_PROTECTION(ht) \
     735             :         ((ht)->u.flags & HASH_FLAG_APPLY_PROTECTION)
     736             : 
     737             : #define ZEND_HASH_APPLY_SHIFT 8
     738             : #define ZEND_HASH_GET_APPLY_COUNT(ht) ((ht)->u.flags >> ZEND_HASH_APPLY_SHIFT)
     739             : #define ZEND_HASH_INC_APPLY_COUNT(ht) ((ht)->u.flags += (1 << ZEND_HASH_APPLY_SHIFT))
     740             : #define ZEND_HASH_DEC_APPLY_COUNT(ht) ((ht)->u.flags -= (1 << ZEND_HASH_APPLY_SHIFT))
     741             : 
     742             : #endif                                                  /* ZEND_HASH_H */
     743             : 
     744             : /*
     745             :  * Local variables:
     746             :  * tab-width: 4
     747             :  * c-basic-offset: 4
     748             :  * indent-tabs-mode: t
     749             :  * End:
     750             :  */

Generated by: LCOV version 1.10

Generated at Wed, 22 Oct 2014 07:24:45 +0000 (2 days ago)

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