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-11-10 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     5014382 :         register const char *tmp = key;
     239             : 
     240     5014382 :         if (*tmp > '9') {
     241     4595625 :                 return 0;
     242      418757 :         } else if (*tmp < '0') {
     243       35694 :                 if (*tmp != '-') {
     244       35613 :                         return 0;
     245             :                 }
     246          81 :                 tmp++;
     247          81 :                 if (*tmp > '9' || *tmp < '0') {
     248          22 :                         return 0;
     249             :                 }
     250             :         }
     251      383122 :         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      269084 :         zv = zend_hash_find(ht, key);
     266      298390 :         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       38406 :         if (ZEND_HANDLE_NUMERIC(key, idx)) {
     294         326 :                 return zend_hash_index_update(ht, idx, pData);
     295             :         } else {
     296       18877 :                 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        1578 :         if (ZEND_HANDLE_NUMERIC(key, idx)) {
     342          28 :                 return zend_hash_index_find(ht, idx);
     343             :         } else {
     344         761 :                 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      277866 :         if (ZEND_HANDLE_NUMERIC(key, idx)) {
     366          20 :                 return zend_hash_index_exists(ht, idx);
     367             :         } else {
     368      138913 :                 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      314807 :         if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
     378        1850 :                 return zend_hash_index_update(ht, idx, pData);
     379             :         } else {
     380      312957 :                 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     1239179 :         if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
     390          28 :                 return zend_hash_index_update(ht, idx, pData);
     391             :         } else {
     392     1239151 :                 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   133691606 :         ZVAL_PTR(&tmp, pData);
     449   133691606 :         zv = zend_hash_add(ht, key, &tmp);
     450   133691606 :         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    27152134 :         ZVAL_PTR(&tmp, pData);
     458    27152134 :         zv = zend_hash_add_new(ht, key, &tmp);
     459    27152134 :         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     8712349 :         ZVAL_PTR(&tmp, pData);
     467     8712349 :         zv = zend_hash_str_add(ht, str, len, &tmp);
     468     8712349 :         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    51887887 :         ZVAL_PTR(&tmp, pData);
     476    51887887 :         zv = zend_hash_update(ht, key, &tmp);
     477    51887887 :         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      988411 :         ZVAL_PTR(&tmp, pData);
     485      988411 :         zv = zend_hash_str_update(ht, str, len, &tmp);
     486      988411 :         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     2579939 :         ZVAL_PTR(&tmp, NULL);
     494     2579939 :         if ((zv = zend_hash_add(ht, key, &tmp))) {
     495     5159874 :                 Z_PTR_P(zv) = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
     496     2579937 :                 memcpy(Z_PTR_P(zv), pData, size);
     497     2579937 :                 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     3364016 :         ZVAL_PTR(&tmp, NULL);
     507     3364016 :         if ((zv = zend_hash_str_add(ht, str, len, &tmp))) {
     508     6687052 :                 Z_PTR_P(zv) = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
     509     3343526 :                 memcpy(Z_PTR_P(zv), pData, size);
     510     3343526 :                 return Z_PTR_P(zv);
     511             :         }
     512       20490 :         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    90674354 :         p = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
     520    45337177 :         memcpy(p, pData, size);
     521    45337177 :         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       51272 :         p = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
     529       25636 :         memcpy(p, pData, size);
     530       25636 :         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     1272653 :         ZVAL_PTR(&tmp, pData);
     538     1272653 :         zv = zend_hash_index_update(ht, h, &tmp);
     539     1272653 :         return zv ? Z_PTR_P(zv) : NULL;
     540             : }
     541             : 
     542             : static zend_always_inline void *zend_hash_index_add_mem(HashTable *ht, zend_ulong h, void *pData, size_t size)
     543             : {
     544             :         zval tmp, *zv;
     545             : 
     546             :         ZVAL_PTR(&tmp, NULL);
     547             :         if ((zv = zend_hash_index_add(ht, h, &tmp))) {
     548             :                 Z_PTR_P(zv) = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
     549             :                 memcpy(Z_PTR_P(zv), pData, size);
     550             :                 return Z_PTR_P(zv);
     551             :         }
     552             :         return NULL;
     553             : }
     554             : 
     555             : static zend_always_inline void *zend_hash_next_index_insert_ptr(HashTable *ht, void *pData)
     556             : {
     557             :         zval tmp, *zv;
     558             : 
     559       38999 :         ZVAL_PTR(&tmp, pData);
     560       38999 :         zv = zend_hash_next_index_insert(ht, &tmp);
     561       38999 :         return zv ? Z_PTR_P(zv) : NULL;
     562             : }
     563             : 
     564             : static zend_always_inline void *zend_hash_index_update_mem(HashTable *ht, zend_ulong h, void *pData, size_t size)
     565             : {
     566             :         void *p;
     567             : 
     568       15302 :         p = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
     569        7651 :         memcpy(p, pData, size);
     570        7651 :         return zend_hash_index_update_ptr(ht, h, p);
     571             : }
     572             : 
     573             : static zend_always_inline void *zend_hash_next_index_insert_mem(HashTable *ht, void *pData, size_t size)
     574             : {
     575             :         zval tmp, *zv;
     576             : 
     577         104 :         ZVAL_PTR(&tmp, NULL);
     578         104 :         if ((zv = zend_hash_next_index_insert(ht, &tmp))) {
     579         208 :                 Z_PTR_P(zv) = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
     580         104 :                 memcpy(Z_PTR_P(zv), pData, size);
     581         104 :                 return Z_PTR_P(zv);
     582             :         }
     583           0 :         return NULL;
     584             : }
     585             : 
     586             : static zend_always_inline void *zend_hash_find_ptr(const HashTable *ht, zend_string *key)
     587             : {
     588             :         zval *zv;
     589             : 
     590    39188230 :         zv = zend_hash_find(ht, key);
     591    41089801 :         return zv ? Z_PTR_P(zv) : NULL;
     592             : }
     593             : 
     594             : static zend_always_inline void *zend_hash_str_find_ptr(const HashTable *ht, const char *str, size_t len)
     595             : {
     596             :         zval *zv;
     597             : 
     598     1977210 :         zv = zend_hash_str_find(ht, str, len);
     599     1977210 :         return zv ? Z_PTR_P(zv) : NULL;
     600             : }
     601             : 
     602             : static zend_always_inline void *zend_hash_index_find_ptr(const HashTable *ht, zend_ulong h)
     603             : {
     604             :         zval *zv;
     605             : 
     606      262989 :         zv = zend_hash_index_find(ht, h);
     607      262989 :         return zv ? Z_PTR_P(zv) : NULL;
     608             : }
     609             : 
     610             : static zend_always_inline void *zend_symtable_str_find_ptr(HashTable *ht, const char *str, size_t len)
     611             : {
     612             :         zend_ulong idx;
     613             : 
     614           0 :         if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
     615           0 :                 return zend_hash_index_find_ptr(ht, idx);
     616             :         } else {
     617           0 :                 return zend_hash_str_find_ptr(ht, str, len);
     618             :         }
     619             : }
     620             : 
     621             : static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, HashPosition *pos)
     622             : {
     623             :         zval *zv;
     624             : 
     625       64298 :         zv = zend_hash_get_current_data_ex(ht, pos);
     626       64298 :         return zv ? Z_PTR_P(zv) : NULL;
     627             : }
     628             : 
     629             : #define zend_hash_get_current_data_ptr(ht) \
     630             :         zend_hash_get_current_data_ptr_ex(ht, &(ht)->nInternalPointer)
     631             : 
     632             : #define ZEND_HASH_FOREACH(_ht, indirect) do { \
     633             :                 uint _idx; \
     634             :                 for (_idx = 0; _idx < (_ht)->nNumUsed; _idx++) { \
     635             :                         Bucket *_p = (_ht)->arData + _idx; \
     636             :                         zval *_z = &_p->val; \
     637             :                         if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \
     638             :                                 _z = Z_INDIRECT_P(_z); \
     639             :                         } \
     640             :                         if (Z_TYPE_P(_z) == IS_UNDEF) continue;
     641             : 
     642             : #define ZEND_HASH_REVERSE_FOREACH(_ht, indirect) do { \
     643             :                 uint _idx; \
     644             :                 for (_idx = (_ht)->nNumUsed; _idx > 0; _idx--) { \
     645             :                         Bucket *_p = (_ht)->arData + _idx - 1; \
     646             :                         zval *_z = &_p->val; \
     647             :                         if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \
     648             :                                 _z = Z_INDIRECT_P(_z); \
     649             :                         } \
     650             :                         if (Z_TYPE_P(_z) == IS_UNDEF) continue;
     651             : 
     652             : #define ZEND_HASH_FOREACH_END() \
     653             :                 } \
     654             :         } while (0)
     655             :         
     656             : #define ZEND_HASH_FOREACH_BUCKET(ht, _bucket) \
     657             :         ZEND_HASH_FOREACH(ht, 0); \
     658             :         _bucket = _p;
     659             : 
     660             : #define ZEND_HASH_FOREACH_VAL(ht, _val) \
     661             :         ZEND_HASH_FOREACH(ht, 0); \
     662             :         _val = _z;
     663             : 
     664             : #define ZEND_HASH_FOREACH_VAL_IND(ht, _val) \
     665             :         ZEND_HASH_FOREACH(ht, 1); \
     666             :         _val = _z;
     667             : 
     668             : #define ZEND_HASH_FOREACH_PTR(ht, _ptr) \
     669             :         ZEND_HASH_FOREACH(ht, 0); \
     670             :         _ptr = Z_PTR_P(_z);
     671             : 
     672             : #define ZEND_HASH_FOREACH_NUM_KEY(ht, _h) \
     673             :         ZEND_HASH_FOREACH(ht, 0); \
     674             :         _h = _p->h;
     675             : 
     676             : #define ZEND_HASH_FOREACH_STR_KEY(ht, _key) \
     677             :         ZEND_HASH_FOREACH(ht, 0); \
     678             :         _key = _p->key;
     679             :                 
     680             : #define ZEND_HASH_FOREACH_KEY(ht, _h, _key) \
     681             :         ZEND_HASH_FOREACH(ht, 0); \
     682             :         _h = _p->h; \
     683             :         _key = _p->key;
     684             : 
     685             : #define ZEND_HASH_FOREACH_NUM_KEY_VAL(ht, _h, _val) \
     686             :         ZEND_HASH_FOREACH(ht, 0); \
     687             :         _h = _p->h; \
     688             :         _val = _z;
     689             :                 
     690             : #define ZEND_HASH_FOREACH_STR_KEY_VAL(ht, _key, _val) \
     691             :         ZEND_HASH_FOREACH(ht, 0); \
     692             :         _key = _p->key; \
     693             :         _val = _z;
     694             : 
     695             : #define ZEND_HASH_FOREACH_KEY_VAL(ht, _h, _key, _val) \
     696             :         ZEND_HASH_FOREACH(ht, 0); \
     697             :         _h = _p->h; \
     698             :         _key = _p->key; \
     699             :         _val = _z;
     700             : 
     701             : #define ZEND_HASH_FOREACH_STR_KEY_VAL_IND(ht, _key, _val) \
     702             :         ZEND_HASH_FOREACH(ht, 1); \
     703             :         _key = _p->key; \
     704             :         _val = _z;
     705             : 
     706             : #define ZEND_HASH_FOREACH_KEY_VAL_IND(ht, _h, _key, _val) \
     707             :         ZEND_HASH_FOREACH(ht, 1); \
     708             :         _h = _p->h; \
     709             :         _key = _p->key; \
     710             :         _val = _z;
     711             : 
     712             : #define ZEND_HASH_FOREACH_NUM_KEY_PTR(ht, _h, _ptr) \
     713             :         ZEND_HASH_FOREACH(ht, 0); \
     714             :         _h = _p->h; \
     715             :         _ptr = Z_PTR_P(_z);
     716             : 
     717             : #define ZEND_HASH_FOREACH_STR_KEY_PTR(ht, _key, _ptr) \
     718             :         ZEND_HASH_FOREACH(ht, 0); \
     719             :         _key = _p->key; \
     720             :         _ptr = Z_PTR_P(_z);
     721             : 
     722             : #define ZEND_HASH_FOREACH_KEY_PTR(ht, _h, _key, _ptr) \
     723             :         ZEND_HASH_FOREACH(ht, 0); \
     724             :         _h = _p->h; \
     725             :         _key = _p->key; \
     726             :         _ptr = Z_PTR_P(_z);
     727             : 
     728             : #define ZEND_HASH_REVERSE_FOREACH_VAL(ht, _val) \
     729             :         ZEND_HASH_REVERSE_FOREACH(ht, 0); \
     730             :         _val = _z;
     731             : 
     732             : #define ZEND_HASH_REVERSE_FOREACH_PTR(ht, _ptr) \
     733             :         ZEND_HASH_REVERSE_FOREACH(ht, 0); \
     734             :         _ptr = Z_PTR_P(_z);
     735             : 
     736             : #define ZEND_HASH_REVERSE_FOREACH_VAL_IND(ht, _val) \
     737             :         ZEND_HASH_REVERSE_FOREACH(ht, 1); \
     738             :         _val = _z;
     739             : 
     740             : #define ZEND_HASH_REVERSE_FOREACH_KEY_VAL(ht, _h, _key, _val) \
     741             :         ZEND_HASH_REVERSE_FOREACH(ht, 0); \
     742             :         _h = _p->h; \
     743             :         _key = _p->key; \
     744             :         _val = _z;
     745             : 
     746             : #define ZEND_HASH_REVERSE_FOREACH_KEY_VAL_IND(ht, _h, _key, _val) \
     747             :         ZEND_HASH_REVERSE_FOREACH(ht, 1); \
     748             :         _h = _p->h; \
     749             :         _key = _p->key; \
     750             :         _val = _z;
     751             : 
     752             : #define ZEND_HASH_APPLY_PROTECTION(ht) \
     753             :         ((ht)->u.flags & HASH_FLAG_APPLY_PROTECTION)
     754             : 
     755             : #define ZEND_HASH_APPLY_SHIFT 8
     756             : #define ZEND_HASH_GET_APPLY_COUNT(ht) ((ht)->u.flags >> ZEND_HASH_APPLY_SHIFT)
     757             : #define ZEND_HASH_INC_APPLY_COUNT(ht) ((ht)->u.flags += (1 << ZEND_HASH_APPLY_SHIFT))
     758             : #define ZEND_HASH_DEC_APPLY_COUNT(ht) ((ht)->u.flags -= (1 << ZEND_HASH_APPLY_SHIFT))
     759             : 
     760             : #endif                                                  /* ZEND_HASH_H */
     761             : 
     762             : /*
     763             :  * Local variables:
     764             :  * tab-width: 4
     765             :  * c-basic-offset: 4
     766             :  * indent-tabs-mode: t
     767             :  * End:
     768             :  */

Generated by: LCOV version 1.10

Generated at Mon, 10 Nov 2014 22:46:35 +0000 (11 days ago)

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