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: 103 105 98.1 %
Date: 2015-03-01 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2015 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             : #define HASH_FLAG_INITIALIZED      (1<<3)
      43             : 
      44             : #define HASH_MASK_CONSISTENCY      0x60
      45             : 
      46             : typedef struct _zend_hash_key {
      47             :         zend_ulong h;
      48             :         zend_string *key;
      49             : } zend_hash_key;
      50             : 
      51             : typedef zend_bool (*merge_checker_func_t)(HashTable *target_ht, zval *source_data, zend_hash_key *hash_key, void *pParam);
      52             : 
      53             : BEGIN_EXTERN_C()
      54             : 
      55             : /* startup/shutdown */
      56             : ZEND_API void _zend_hash_init(HashTable *ht, uint32_t nSize, dtor_func_t pDestructor, zend_bool persistent ZEND_FILE_LINE_DC);
      57             : 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);
      58             : ZEND_API void zend_hash_destroy(HashTable *ht);
      59             : ZEND_API void zend_hash_clean(HashTable *ht);
      60             : #define zend_hash_init(ht, nSize, pHashFunction, pDestructor, persistent)                                               _zend_hash_init((ht), (nSize), (pDestructor), (persistent) ZEND_FILE_LINE_CC)
      61             : #define zend_hash_init_ex(ht, nSize, pHashFunction, pDestructor, persistent, bApplyProtection)          _zend_hash_init_ex((ht), (nSize), (pDestructor), (persistent), (bApplyProtection) ZEND_FILE_LINE_CC)
      62             : 
      63             : ZEND_API void zend_hash_real_init(HashTable *ht, zend_bool packed);
      64             : ZEND_API void zend_hash_packed_to_hash(HashTable *ht);
      65             : ZEND_API void zend_hash_to_packed(HashTable *ht);
      66             : 
      67             : /* additions/updates/changes */
      68             : ZEND_API zval *_zend_hash_add_or_update(HashTable *ht, zend_string *key, zval *pData, uint32_t flag ZEND_FILE_LINE_DC);
      69             : ZEND_API zval *_zend_hash_update(HashTable *ht, zend_string *key,zval *pData ZEND_FILE_LINE_DC);
      70             : ZEND_API zval *_zend_hash_update_ind(HashTable *ht, zend_string *key,zval *pData ZEND_FILE_LINE_DC);
      71             : ZEND_API zval *_zend_hash_add(HashTable *ht, zend_string *key,zval *pData ZEND_FILE_LINE_DC);
      72             : ZEND_API zval *_zend_hash_add_new(HashTable *ht, zend_string *key,zval *pData ZEND_FILE_LINE_DC);
      73             : 
      74             : #define zend_hash_update(ht, key, pData) \
      75             :                 _zend_hash_update(ht, key, pData ZEND_FILE_LINE_CC)
      76             : #define zend_hash_update_ind(ht, key, pData) \
      77             :                 _zend_hash_update_ind(ht, key, pData ZEND_FILE_LINE_CC)
      78             : #define zend_hash_add(ht, key, pData) \
      79             :                 _zend_hash_add(ht, key, pData ZEND_FILE_LINE_CC)
      80             : #define zend_hash_add_new(ht, key, pData) \
      81             :                 _zend_hash_add_new(ht, key, pData ZEND_FILE_LINE_CC)
      82             : 
      83             : 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);
      84             : ZEND_API zval *_zend_hash_str_update(HashTable *ht, const char *key, size_t len, zval *pData ZEND_FILE_LINE_DC);
      85             : ZEND_API zval *_zend_hash_str_update_ind(HashTable *ht, const char *key, size_t len, zval *pData ZEND_FILE_LINE_DC);
      86             : ZEND_API zval *_zend_hash_str_add(HashTable *ht, const char *key, size_t len, zval *pData ZEND_FILE_LINE_DC);
      87             : ZEND_API zval *_zend_hash_str_add_new(HashTable *ht, const char *key, size_t len, zval *pData ZEND_FILE_LINE_DC);
      88             : 
      89             : #define zend_hash_str_update(ht, key, len, pData) \
      90             :                 _zend_hash_str_update(ht, key, len, pData ZEND_FILE_LINE_CC)
      91             : #define zend_hash_str_update_ind(ht, key, len, pData) \
      92             :                 _zend_hash_str_update_ind(ht, key, len, pData ZEND_FILE_LINE_CC)
      93             : #define zend_hash_str_add(ht, key, len, pData) \
      94             :                 _zend_hash_str_add(ht, key, len, pData ZEND_FILE_LINE_CC)
      95             : #define zend_hash_str_add_new(ht, key, len, pData) \
      96             :                 _zend_hash_str_add_new(ht, key, len, pData ZEND_FILE_LINE_CC)
      97             : 
      98             : ZEND_API zval *_zend_hash_index_add_or_update(HashTable *ht, zend_ulong h, zval *pData, uint32_t flag ZEND_FILE_LINE_DC);
      99             : ZEND_API zval *_zend_hash_index_add(HashTable *ht, zend_ulong h, zval *pData ZEND_FILE_LINE_DC);
     100             : ZEND_API zval *_zend_hash_index_add_new(HashTable *ht, zend_ulong h, zval *pData ZEND_FILE_LINE_DC);
     101             : ZEND_API zval *_zend_hash_index_update(HashTable *ht, zend_ulong h, zval *pData ZEND_FILE_LINE_DC);
     102             : ZEND_API zval *_zend_hash_next_index_insert(HashTable *ht, zval *pData ZEND_FILE_LINE_DC);
     103             : ZEND_API zval *_zend_hash_next_index_insert_new(HashTable *ht, zval *pData ZEND_FILE_LINE_DC);
     104             : 
     105             : #define zend_hash_index_add(ht, h, pData) \
     106             :                 _zend_hash_index_add(ht, h, pData ZEND_FILE_LINE_CC)
     107             : #define zend_hash_index_add_new(ht, h, pData) \
     108             :                 _zend_hash_index_add_new(ht, h, pData ZEND_FILE_LINE_CC)
     109             : #define zend_hash_index_update(ht, h, pData) \
     110             :                 _zend_hash_index_update(ht, h, pData ZEND_FILE_LINE_CC)
     111             : #define zend_hash_next_index_insert(ht, pData) \
     112             :                 _zend_hash_next_index_insert(ht, pData ZEND_FILE_LINE_CC)
     113             : #define zend_hash_next_index_insert_new(ht, pData) \
     114             :                 _zend_hash_next_index_insert_new(ht, pData ZEND_FILE_LINE_CC)
     115             : 
     116             : ZEND_API zval *zend_hash_index_add_empty_element(HashTable *ht, zend_ulong h);
     117             : ZEND_API zval *zend_hash_add_empty_element(HashTable *ht, zend_string *key);
     118             : ZEND_API zval *zend_hash_str_add_empty_element(HashTable *ht, const char *key, size_t len);
     119             : 
     120             : #define ZEND_HASH_APPLY_KEEP                            0
     121             : #define ZEND_HASH_APPLY_REMOVE                          1<<0
     122             : #define ZEND_HASH_APPLY_STOP                            1<<1
     123             : 
     124             : typedef int (*apply_func_t)(zval *pDest);
     125             : typedef int (*apply_func_arg_t)(zval *pDest, void *argument);
     126             : typedef int (*apply_func_args_t)(zval *pDest, int num_args, va_list args, zend_hash_key *hash_key);
     127             : 
     128             : ZEND_API void zend_hash_graceful_destroy(HashTable *ht);
     129             : ZEND_API void zend_hash_graceful_reverse_destroy(HashTable *ht);
     130             : ZEND_API void zend_hash_apply(HashTable *ht, apply_func_t apply_func);
     131             : ZEND_API void zend_hash_apply_with_argument(HashTable *ht, apply_func_arg_t apply_func, void *);
     132             : ZEND_API void zend_hash_apply_with_arguments(HashTable *ht, apply_func_args_t apply_func, int, ...);
     133             : 
     134             : /* This function should be used with special care (in other words,
     135             :  * it should usually not be used).  When used with the ZEND_HASH_APPLY_STOP
     136             :  * return value, it assumes things about the order of the elements in the hash.
     137             :  * Also, it does not provide the same kind of reentrancy protection that
     138             :  * the standard apply functions do.
     139             :  */
     140             : ZEND_API void zend_hash_reverse_apply(HashTable *ht, apply_func_t apply_func);
     141             : 
     142             : 
     143             : /* Deletes */
     144             : ZEND_API int zend_hash_del(HashTable *ht, zend_string *key);
     145             : ZEND_API int zend_hash_del_ind(HashTable *ht, zend_string *key);
     146             : ZEND_API int zend_hash_str_del(HashTable *ht, const char *key, size_t len);
     147             : ZEND_API int zend_hash_str_del_ind(HashTable *ht, const char *key, size_t len);
     148             : ZEND_API int zend_hash_index_del(HashTable *ht, zend_ulong h);
     149             : 
     150             : /* Data retreival */
     151             : ZEND_API zval *zend_hash_find(const HashTable *ht, zend_string *key);
     152             : ZEND_API zval *zend_hash_str_find(const HashTable *ht, const char *key, size_t len);
     153             : ZEND_API zval *zend_hash_index_find(const HashTable *ht, zend_ulong h);
     154             : 
     155             : /* Misc */
     156             : ZEND_API zend_bool zend_hash_exists(const HashTable *ht, zend_string *key);
     157             : ZEND_API zend_bool zend_hash_str_exists(const HashTable *ht, const char *str, size_t len);
     158             : ZEND_API zend_bool zend_hash_index_exists(const HashTable *ht, zend_ulong h);
     159             : 
     160             : /* traversing */
     161             : #define zend_hash_has_more_elements_ex(ht, pos) \
     162             :         (zend_hash_get_current_key_type_ex(ht, pos) == HASH_KEY_NON_EXISTENT ? FAILURE : SUCCESS)
     163             : ZEND_API int zend_hash_move_forward_ex(HashTable *ht, HashPosition *pos);
     164             : ZEND_API int zend_hash_move_backwards_ex(HashTable *ht, HashPosition *pos);
     165             : ZEND_API int zend_hash_get_current_key_ex(const HashTable *ht, zend_string **str_index, zend_ulong *num_index, HashPosition *pos);
     166             : ZEND_API void zend_hash_get_current_key_zval_ex(const HashTable *ht, zval *key, HashPosition *pos);
     167             : ZEND_API int zend_hash_get_current_key_type_ex(HashTable *ht, HashPosition *pos);
     168             : ZEND_API zval *zend_hash_get_current_data_ex(HashTable *ht, HashPosition *pos);
     169             : ZEND_API void zend_hash_internal_pointer_reset_ex(HashTable *ht, HashPosition *pos);
     170             : ZEND_API void zend_hash_internal_pointer_end_ex(HashTable *ht, HashPosition *pos);
     171             : 
     172             : #define zend_hash_has_more_elements(ht) \
     173             :         zend_hash_has_more_elements_ex(ht, &(ht)->nInternalPointer)
     174             : #define zend_hash_move_forward(ht) \
     175             :         zend_hash_move_forward_ex(ht, &(ht)->nInternalPointer)
     176             : #define zend_hash_move_backwards(ht) \
     177             :         zend_hash_move_backwards_ex(ht, &(ht)->nInternalPointer)
     178             : #define zend_hash_get_current_key(ht, str_index, num_index) \
     179             :         zend_hash_get_current_key_ex(ht, str_index, num_index, &(ht)->nInternalPointer)
     180             : #define zend_hash_get_current_key_zval(ht, key) \
     181             :         zend_hash_get_current_key_zval_ex(ht, key, &(ht)->nInternalPointer)
     182             : #define zend_hash_get_current_key_type(ht) \
     183             :         zend_hash_get_current_key_type_ex(ht, &(ht)->nInternalPointer)
     184             : #define zend_hash_get_current_data(ht) \
     185             :         zend_hash_get_current_data_ex(ht, &(ht)->nInternalPointer)
     186             : #define zend_hash_internal_pointer_reset(ht) \
     187             :         zend_hash_internal_pointer_reset_ex(ht, &(ht)->nInternalPointer)
     188             : #define zend_hash_internal_pointer_end(ht) \
     189             :         zend_hash_internal_pointer_end_ex(ht, &(ht)->nInternalPointer)
     190             : 
     191             : /* Copying, merging and sorting */
     192             : ZEND_API void zend_hash_copy(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor);
     193             : ZEND_API void _zend_hash_merge(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, zend_bool overwrite ZEND_FILE_LINE_DC);
     194             : ZEND_API void zend_hash_merge_ex(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, merge_checker_func_t pMergeSource, void *pParam);
     195             : ZEND_API void zend_hash_bucket_swap(Bucket *p, Bucket *q);
     196             : ZEND_API void zend_hash_bucket_renum_swap(Bucket *p, Bucket *q);
     197             : ZEND_API void zend_hash_bucket_packed_swap(Bucket *p, Bucket *q);
     198             : ZEND_API int zend_hash_sort_ex(HashTable *ht, sort_func_t sort_func, compare_func_t compare_func, zend_bool renumber);
     199             : ZEND_API int zend_hash_compare(HashTable *ht1, HashTable *ht2, compare_func_t compar, zend_bool ordered);
     200             : ZEND_API zval *zend_hash_minmax(const HashTable *ht, compare_func_t compar, uint32_t flag);
     201             : 
     202             : #define zend_hash_merge(target, source, pCopyConstructor, overwrite)                                    \
     203             :         _zend_hash_merge(target, source, pCopyConstructor, overwrite ZEND_FILE_LINE_CC)
     204             : 
     205             : #define zend_hash_sort(ht, compare_func, renumber) \
     206             :         zend_hash_sort_ex(ht, zend_sort, compare_func, renumber)
     207             : 
     208             : #define zend_hash_num_elements(ht) \
     209             :         (ht)->nNumOfElements
     210             : 
     211             : #define zend_hash_next_free_element(ht) \
     212             :         (ht)->nNextFreeElement
     213             : 
     214             : ZEND_API int zend_hash_rehash(HashTable *ht);
     215             : 
     216             : ZEND_API HashTable *zend_array_dup(HashTable *source);
     217             : ZEND_API void zend_array_destroy(HashTable *ht);
     218             : ZEND_API void zend_symtable_clean(HashTable *ht);
     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             : 
     229             : ZEND_API uint32_t     zend_hash_iterator_add(HashTable *ht, HashPosition pos);
     230             : ZEND_API HashPosition zend_hash_iterator_pos(uint32_t idx, HashTable *ht);
     231             : ZEND_API void         zend_hash_iterator_del(uint32_t idx);
     232             : ZEND_API HashPosition zend_hash_iterators_lower_pos(HashTable *ht, HashPosition start);
     233             : ZEND_API void        _zend_hash_iterators_update(HashTable *ht, HashPosition from, HashPosition to);
     234             : 
     235             : static zend_always_inline void zend_hash_iterators_update(HashTable *ht, HashPosition from, HashPosition to)
     236             : {
     237   271059579 :         if (UNEXPECTED(ht->u.v.nIteratorsCount)) {
     238         204 :                 _zend_hash_iterators_update(ht, from, to);
     239             :         }
     240             : }
     241             : 
     242             : 
     243             : END_EXTERN_C()
     244             : 
     245             : #define ZEND_INIT_SYMTABLE(ht)                                                          \
     246             :         ZEND_INIT_SYMTABLE_EX(ht, 8, 0)
     247             : 
     248             : #define ZEND_INIT_SYMTABLE_EX(ht, n, persistent)                        \
     249             :         zend_hash_init(ht, n, NULL, ZVAL_PTR_DTOR, persistent)
     250             : 
     251             : static zend_always_inline int _zend_handle_numeric_str(const char *key, size_t length, zend_ulong *idx)
     252             : {
     253     5087840 :         register const char *tmp = key;
     254             : 
     255     5087840 :         if (*tmp > '9') {
     256     4668859 :                 return 0;
     257      418981 :         } else if (*tmp < '0') {
     258       35915 :                 if (*tmp != '-') {
     259       35834 :                         return 0;
     260             :                 }
     261          81 :                 tmp++;
     262          81 :                 if (*tmp > '9' || *tmp < '0') {
     263          22 :                         return 0;
     264             :                 }
     265             :         }
     266      383125 :         return _zend_handle_numeric_str_ex(key, length, idx);
     267             : }
     268             : 
     269             : #define ZEND_HANDLE_NUMERIC_STR(key, length, idx) \
     270             :         _zend_handle_numeric_str(key, length, &idx)
     271             : 
     272             : #define ZEND_HANDLE_NUMERIC(key, idx) \
     273             :         ZEND_HANDLE_NUMERIC_STR((key)->val, (key)->len, idx)
     274             : 
     275             : 
     276             : static zend_always_inline zval *zend_hash_find_ind(const HashTable *ht, zend_string *key)
     277             : {
     278             :         zval *zv;
     279             : 
     280      273435 :         zv = zend_hash_find(ht, key);
     281      303219 :         return (zv && Z_TYPE_P(zv) == IS_INDIRECT) ? Z_INDIRECT_P(zv) : zv;
     282             : }
     283             : 
     284             : 
     285             : static zend_always_inline int zend_hash_exists_ind(const HashTable *ht, zend_string *key)
     286             : {
     287             :         zval *zv;
     288             : 
     289         219 :         zv = zend_hash_find(ht, key);
     290         378 :         return zv && (Z_TYPE_P(zv) != IS_INDIRECT ||
     291          27 :                         Z_TYPE_P(Z_INDIRECT_P(zv)) != IS_UNDEF);
     292             : }
     293             : 
     294             : 
     295             : static zend_always_inline zval *zend_hash_str_find_ind(const HashTable *ht, const char *str, size_t len)
     296             : {
     297             :         zval *zv;
     298             : 
     299         737 :         zv = zend_hash_str_find(ht, str, len);
     300        1471 :         return (zv && Z_TYPE_P(zv) == IS_INDIRECT) ? Z_INDIRECT_P(zv) : zv;
     301             : }
     302             : 
     303             : 
     304             : static zend_always_inline zval *zend_symtable_update(HashTable *ht, zend_string *key, zval *pData)
     305             : {
     306             :         zend_ulong idx;
     307             : 
     308       38326 :         if (ZEND_HANDLE_NUMERIC(key, idx)) {
     309         325 :                 return zend_hash_index_update(ht, idx, pData);
     310             :         } else {
     311       18838 :                 return zend_hash_update(ht, key, pData);
     312             :         }
     313             : }
     314             : 
     315             : 
     316             : static zend_always_inline zval *zend_symtable_update_ind(HashTable *ht, zend_string *key, zval *pData)
     317             : {
     318             :         zend_ulong idx;
     319             : 
     320         118 :         if (ZEND_HANDLE_NUMERIC(key, idx)) {
     321           1 :                 return zend_hash_index_update(ht, idx, pData);
     322             :         } else {
     323          58 :                 return zend_hash_update_ind(ht, key, pData);
     324             :         }
     325             : }
     326             : 
     327             : 
     328             : static zend_always_inline int zend_symtable_del(HashTable *ht, zend_string *key)
     329             : {
     330             :         zend_ulong idx;
     331             : 
     332          32 :         if (ZEND_HANDLE_NUMERIC(key, idx)) {
     333           6 :                 return zend_hash_index_del(ht, idx);
     334             :         } else {
     335          10 :                 return zend_hash_del(ht, key);
     336             :         }
     337             : }
     338             : 
     339             : 
     340             : static zend_always_inline int zend_symtable_del_ind(HashTable *ht, zend_string *key)
     341             : {
     342             :         zend_ulong idx;
     343             : 
     344             :         if (ZEND_HANDLE_NUMERIC(key, idx)) {
     345             :                 return zend_hash_index_del(ht, idx);
     346             :         } else {
     347             :                 return zend_hash_del_ind(ht, key);
     348             :         }
     349             : }
     350             : 
     351             : 
     352             : static zend_always_inline zval *zend_symtable_find(const HashTable *ht, zend_string *key)
     353             : {
     354             :         zend_ulong idx;
     355             : 
     356         776 :         if (ZEND_HANDLE_NUMERIC(key, idx)) {
     357          27 :                 return zend_hash_index_find(ht, idx);
     358             :         } else {
     359         361 :                 return zend_hash_find(ht, key);
     360             :         }
     361             : }
     362             : 
     363             : 
     364             : static zend_always_inline zval *zend_symtable_find_ind(const HashTable *ht, zend_string *key)
     365             : {
     366             :         zend_ulong idx;
     367             : 
     368             :         if (ZEND_HANDLE_NUMERIC(key, idx)) {
     369             :                 return zend_hash_index_find(ht, idx);
     370             :         } else {
     371             :                 return zend_hash_find_ind(ht, key);
     372             :         }
     373             : }
     374             : 
     375             : 
     376             : static zend_always_inline int zend_symtable_exists(HashTable *ht, zend_string *key)
     377             : {
     378             :         zend_ulong idx;
     379             : 
     380      282706 :         if (ZEND_HANDLE_NUMERIC(key, idx)) {
     381          20 :                 return zend_hash_index_exists(ht, idx);
     382             :         } else {
     383      141333 :                 return zend_hash_exists(ht, key);
     384             :         }
     385             : }
     386             : 
     387             : 
     388             : static zend_always_inline zval *zend_symtable_str_update(HashTable *ht, const char *str, size_t len, zval *pData)
     389             : {
     390             :         zend_ulong idx;
     391             : 
     392      321551 :         if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
     393        1850 :                 return zend_hash_index_update(ht, idx, pData);
     394             :         } else {
     395      319701 :                 return zend_hash_str_update(ht, str, len, pData);
     396             :         }
     397             : }
     398             : 
     399             : 
     400             : static zend_always_inline zval *zend_symtable_str_update_ind(HashTable *ht, const char *str, size_t len, zval *pData)
     401             : {
     402             :         zend_ulong idx;
     403             : 
     404     1262650 :         if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
     405          28 :                 return zend_hash_index_update(ht, idx, pData);
     406             :         } else {
     407     1262622 :                 return zend_hash_str_update_ind(ht, str, len, pData);
     408             :         }
     409             : }
     410             : 
     411             : 
     412             : static zend_always_inline int zend_symtable_str_del(HashTable *ht, const char *str, size_t len)
     413             : {
     414             :         zend_ulong idx;
     415             : 
     416           8 :         if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
     417           2 :                 return zend_hash_index_del(ht, idx);
     418             :         } else {
     419           6 :                 return zend_hash_str_del(ht, str, len);
     420             :         }
     421             : }
     422             : 
     423             : 
     424             : static zend_always_inline int zend_symtable_str_del_ind(HashTable *ht, const char *str, size_t len)
     425             : {
     426             :         zend_ulong idx;
     427             : 
     428             :         if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
     429             :                 return zend_hash_index_del(ht, idx);
     430             :         } else {
     431             :                 return zend_hash_str_del_ind(ht, str, len);
     432             :         }
     433             : }
     434             : 
     435             : 
     436             : static zend_always_inline zval *zend_symtable_str_find(HashTable *ht, const char *str, size_t len)
     437             : {
     438             :         zend_ulong idx;
     439             : 
     440         434 :         if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
     441          23 :                 return zend_hash_index_find(ht, idx);
     442             :         } else {
     443         411 :                 return zend_hash_str_find(ht, str, len);
     444             :         }
     445             : }
     446             : 
     447             : 
     448             : static zend_always_inline int zend_symtable_str_exists(HashTable *ht, const char *str, size_t len)
     449             : {
     450             :         zend_ulong idx;
     451             : 
     452          75 :         if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
     453           0 :                 return zend_hash_index_exists(ht, idx);
     454             :         } else {
     455          75 :                 return zend_hash_str_exists(ht, str, len);
     456             :         }
     457             : }
     458             : 
     459             : static zend_always_inline void *zend_hash_add_ptr(HashTable *ht, zend_string *key, void *pData)
     460             : {
     461             :         zval tmp, *zv;
     462             : 
     463   133993752 :         ZVAL_PTR(&tmp, pData);
     464   133993752 :         zv = zend_hash_add(ht, key, &tmp);
     465   133993752 :         return zv ? Z_PTR_P(zv) : NULL;
     466             : }
     467             : 
     468             : static zend_always_inline void *zend_hash_add_new_ptr(HashTable *ht, zend_string *key, void *pData)
     469             : {
     470             :         zval tmp, *zv;
     471             : 
     472    27678824 :         ZVAL_PTR(&tmp, pData);
     473    27678824 :         zv = zend_hash_add_new(ht, key, &tmp);
     474    27678824 :         return zv ? Z_PTR_P(zv) : NULL;
     475             : }
     476             : 
     477             : static zend_always_inline void *zend_hash_str_add_ptr(HashTable *ht, const char *str, size_t len, void *pData)
     478             : {
     479             :         zval tmp, *zv;
     480             : 
     481     8881415 :         ZVAL_PTR(&tmp, pData);
     482     8881415 :         zv = zend_hash_str_add(ht, str, len, &tmp);
     483     8881415 :         return zv ? Z_PTR_P(zv) : NULL;
     484             : }
     485             : 
     486             : static zend_always_inline void *zend_hash_update_ptr(HashTable *ht, zend_string *key, void *pData)
     487             : {
     488             :         zval tmp, *zv;
     489             : 
     490    50888826 :         ZVAL_PTR(&tmp, pData);
     491    50888826 :         zv = zend_hash_update(ht, key, &tmp);
     492    50888826 :         return zv ? Z_PTR_P(zv) : NULL;
     493             : }
     494             : 
     495             : static zend_always_inline void *zend_hash_str_update_ptr(HashTable *ht, const char *str, size_t len, void *pData)
     496             : {
     497             :         zval tmp, *zv;
     498             : 
     499     1007196 :         ZVAL_PTR(&tmp, pData);
     500     1007196 :         zv = zend_hash_str_update(ht, str, len, &tmp);
     501     1007196 :         return zv ? Z_PTR_P(zv) : NULL;
     502             : }
     503             : 
     504             : static zend_always_inline void *zend_hash_add_mem(HashTable *ht, zend_string *key, void *pData, size_t size)
     505             : {
     506             :         zval tmp, *zv;
     507             : 
     508     2609338 :         ZVAL_PTR(&tmp, NULL);
     509     2609338 :         if ((zv = zend_hash_add(ht, key, &tmp))) {
     510     5218672 :                 Z_PTR_P(zv) = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
     511     2609336 :                 memcpy(Z_PTR_P(zv), pData, size);
     512     2609336 :                 return Z_PTR_P(zv);
     513             :         }
     514           2 :         return NULL;
     515             : }
     516             : 
     517             : static zend_always_inline void *zend_hash_str_add_mem(HashTable *ht, const char *str, size_t len, void *pData, size_t size)
     518             : {
     519             :         zval tmp, *zv;
     520             : 
     521     3429315 :         ZVAL_PTR(&tmp, NULL);
     522     3429315 :         if ((zv = zend_hash_str_add(ht, str, len, &tmp))) {
     523     6816854 :                 Z_PTR_P(zv) = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
     524     3408427 :                 memcpy(Z_PTR_P(zv), pData, size);
     525     3408427 :                 return Z_PTR_P(zv);
     526             :         }
     527       20888 :         return NULL;
     528             : }
     529             : 
     530             : static zend_always_inline void *zend_hash_update_mem(HashTable *ht, zend_string *key, void *pData, size_t size)
     531             : {
     532             :         void *p;
     533             : 
     534    88338350 :         p = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
     535    44169175 :         memcpy(p, pData, size);
     536    44169175 :         return zend_hash_update_ptr(ht, key, p);
     537             : }
     538             : 
     539             : static zend_always_inline void *zend_hash_str_update_mem(HashTable *ht, const char *str, size_t len, void *pData, size_t size)
     540             : {
     541             :         void *p;
     542             : 
     543       51420 :         p = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
     544       25710 :         memcpy(p, pData, size);
     545       25710 :         return zend_hash_str_update_ptr(ht, str, len, p);
     546             : }
     547             : 
     548             : static zend_always_inline void *zend_hash_index_update_ptr(HashTable *ht, zend_ulong h, void *pData)
     549             : {
     550             :         zval tmp, *zv;
     551             : 
     552     1297032 :         ZVAL_PTR(&tmp, pData);
     553     1297032 :         zv = zend_hash_index_update(ht, h, &tmp);
     554     1297032 :         return zv ? Z_PTR_P(zv) : NULL;
     555             : }
     556             : 
     557             : static zend_always_inline void *zend_hash_index_add_mem(HashTable *ht, zend_ulong h, void *pData, size_t size)
     558             : {
     559             :         zval tmp, *zv;
     560             : 
     561             :         ZVAL_PTR(&tmp, NULL);
     562             :         if ((zv = zend_hash_index_add(ht, h, &tmp))) {
     563             :                 Z_PTR_P(zv) = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
     564             :                 memcpy(Z_PTR_P(zv), pData, size);
     565             :                 return Z_PTR_P(zv);
     566             :         }
     567             :         return NULL;
     568             : }
     569             : 
     570             : static zend_always_inline void *zend_hash_next_index_insert_ptr(HashTable *ht, void *pData)
     571             : {
     572             :         zval tmp, *zv;
     573             : 
     574       39012 :         ZVAL_PTR(&tmp, pData);
     575       39012 :         zv = zend_hash_next_index_insert(ht, &tmp);
     576       39012 :         return zv ? Z_PTR_P(zv) : NULL;
     577             : }
     578             : 
     579             : static zend_always_inline void *zend_hash_index_update_mem(HashTable *ht, zend_ulong h, void *pData, size_t size)
     580             : {
     581             :         void *p;
     582             : 
     583       15302 :         p = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
     584        7651 :         memcpy(p, pData, size);
     585        7651 :         return zend_hash_index_update_ptr(ht, h, p);
     586             : }
     587             : 
     588             : static zend_always_inline void *zend_hash_next_index_insert_mem(HashTable *ht, void *pData, size_t size)
     589             : {
     590             :         zval tmp, *zv;
     591             : 
     592          75 :         ZVAL_PTR(&tmp, NULL);
     593          75 :         if ((zv = zend_hash_next_index_insert(ht, &tmp))) {
     594         150 :                 Z_PTR_P(zv) = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
     595          75 :                 memcpy(Z_PTR_P(zv), pData, size);
     596          75 :                 return Z_PTR_P(zv);
     597             :         }
     598           0 :         return NULL;
     599             : }
     600             : 
     601             : static zend_always_inline void *zend_hash_find_ptr(const HashTable *ht, zend_string *key)
     602             : {
     603             :         zval *zv;
     604             : 
     605    41619814 :         zv = zend_hash_find(ht, key);
     606    41619814 :         return zv ? Z_PTR_P(zv) : NULL;
     607             : }
     608             : 
     609             : static zend_always_inline void *zend_hash_str_find_ptr(const HashTable *ht, const char *str, size_t len)
     610             : {
     611             :         zval *zv;
     612             : 
     613     2012171 :         zv = zend_hash_str_find(ht, str, len);
     614     2012171 :         return zv ? Z_PTR_P(zv) : NULL;
     615             : }
     616             : 
     617             : static zend_always_inline void *zend_hash_index_find_ptr(const HashTable *ht, zend_ulong h)
     618             : {
     619             :         zval *zv;
     620             : 
     621      266898 :         zv = zend_hash_index_find(ht, h);
     622      266898 :         return zv ? Z_PTR_P(zv) : NULL;
     623             : }
     624             : 
     625             : static zend_always_inline void *zend_symtable_str_find_ptr(HashTable *ht, const char *str, size_t len)
     626             : {
     627             :         zend_ulong idx;
     628             : 
     629             :         if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
     630             :                 return zend_hash_index_find_ptr(ht, idx);
     631             :         } else {
     632             :                 return zend_hash_str_find_ptr(ht, str, len);
     633             :         }
     634             : }
     635             : 
     636             : static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, HashPosition *pos)
     637             : {
     638             :         zval *zv;
     639             : 
     640       46396 :         zv = zend_hash_get_current_data_ex(ht, pos);
     641       46396 :         return zv ? Z_PTR_P(zv) : NULL;
     642             : }
     643             : 
     644             : #define zend_hash_get_current_data_ptr(ht) \
     645             :         zend_hash_get_current_data_ptr_ex(ht, &(ht)->nInternalPointer)
     646             : 
     647             : #define ZEND_HASH_FOREACH(_ht, indirect) do { \
     648             :                 uint _idx; \
     649             :                 for (_idx = 0; _idx < (_ht)->nNumUsed; _idx++) { \
     650             :                         Bucket *_p = (_ht)->arData + _idx; \
     651             :                         zval *_z = &_p->val; \
     652             :                         if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \
     653             :                                 _z = Z_INDIRECT_P(_z); \
     654             :                         } \
     655             :                         if (Z_TYPE_P(_z) == IS_UNDEF) continue;
     656             : 
     657             : #define ZEND_HASH_REVERSE_FOREACH(_ht, indirect) do { \
     658             :                 uint _idx; \
     659             :                 for (_idx = (_ht)->nNumUsed; _idx > 0; _idx--) { \
     660             :                         Bucket *_p = (_ht)->arData + _idx - 1; \
     661             :                         zval *_z = &_p->val; \
     662             :                         if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \
     663             :                                 _z = Z_INDIRECT_P(_z); \
     664             :                         } \
     665             :                         if (Z_TYPE_P(_z) == IS_UNDEF) continue;
     666             : 
     667             : #define ZEND_HASH_FOREACH_END() \
     668             :                 } \
     669             :         } while (0)
     670             : 
     671             : #define ZEND_HASH_FOREACH_BUCKET(ht, _bucket) \
     672             :         ZEND_HASH_FOREACH(ht, 0); \
     673             :         _bucket = _p;
     674             : 
     675             : #define ZEND_HASH_FOREACH_VAL(ht, _val) \
     676             :         ZEND_HASH_FOREACH(ht, 0); \
     677             :         _val = _z;
     678             : 
     679             : #define ZEND_HASH_FOREACH_VAL_IND(ht, _val) \
     680             :         ZEND_HASH_FOREACH(ht, 1); \
     681             :         _val = _z;
     682             : 
     683             : #define ZEND_HASH_FOREACH_PTR(ht, _ptr) \
     684             :         ZEND_HASH_FOREACH(ht, 0); \
     685             :         _ptr = Z_PTR_P(_z);
     686             : 
     687             : #define ZEND_HASH_FOREACH_NUM_KEY(ht, _h) \
     688             :         ZEND_HASH_FOREACH(ht, 0); \
     689             :         _h = _p->h;
     690             : 
     691             : #define ZEND_HASH_FOREACH_STR_KEY(ht, _key) \
     692             :         ZEND_HASH_FOREACH(ht, 0); \
     693             :         _key = _p->key;
     694             : 
     695             : #define ZEND_HASH_FOREACH_KEY(ht, _h, _key) \
     696             :         ZEND_HASH_FOREACH(ht, 0); \
     697             :         _h = _p->h; \
     698             :         _key = _p->key;
     699             : 
     700             : #define ZEND_HASH_FOREACH_NUM_KEY_VAL(ht, _h, _val) \
     701             :         ZEND_HASH_FOREACH(ht, 0); \
     702             :         _h = _p->h; \
     703             :         _val = _z;
     704             : 
     705             : #define ZEND_HASH_FOREACH_STR_KEY_VAL(ht, _key, _val) \
     706             :         ZEND_HASH_FOREACH(ht, 0); \
     707             :         _key = _p->key; \
     708             :         _val = _z;
     709             : 
     710             : #define ZEND_HASH_FOREACH_KEY_VAL(ht, _h, _key, _val) \
     711             :         ZEND_HASH_FOREACH(ht, 0); \
     712             :         _h = _p->h; \
     713             :         _key = _p->key; \
     714             :         _val = _z;
     715             : 
     716             : #define ZEND_HASH_FOREACH_STR_KEY_VAL_IND(ht, _key, _val) \
     717             :         ZEND_HASH_FOREACH(ht, 1); \
     718             :         _key = _p->key; \
     719             :         _val = _z;
     720             : 
     721             : #define ZEND_HASH_FOREACH_KEY_VAL_IND(ht, _h, _key, _val) \
     722             :         ZEND_HASH_FOREACH(ht, 1); \
     723             :         _h = _p->h; \
     724             :         _key = _p->key; \
     725             :         _val = _z;
     726             : 
     727             : #define ZEND_HASH_FOREACH_NUM_KEY_PTR(ht, _h, _ptr) \
     728             :         ZEND_HASH_FOREACH(ht, 0); \
     729             :         _h = _p->h; \
     730             :         _ptr = Z_PTR_P(_z);
     731             : 
     732             : #define ZEND_HASH_FOREACH_STR_KEY_PTR(ht, _key, _ptr) \
     733             :         ZEND_HASH_FOREACH(ht, 0); \
     734             :         _key = _p->key; \
     735             :         _ptr = Z_PTR_P(_z);
     736             : 
     737             : #define ZEND_HASH_FOREACH_KEY_PTR(ht, _h, _key, _ptr) \
     738             :         ZEND_HASH_FOREACH(ht, 0); \
     739             :         _h = _p->h; \
     740             :         _key = _p->key; \
     741             :         _ptr = Z_PTR_P(_z);
     742             : 
     743             : #define ZEND_HASH_REVERSE_FOREACH_VAL(ht, _val) \
     744             :         ZEND_HASH_REVERSE_FOREACH(ht, 0); \
     745             :         _val = _z;
     746             : 
     747             : #define ZEND_HASH_REVERSE_FOREACH_PTR(ht, _ptr) \
     748             :         ZEND_HASH_REVERSE_FOREACH(ht, 0); \
     749             :         _ptr = Z_PTR_P(_z);
     750             : 
     751             : #define ZEND_HASH_REVERSE_FOREACH_VAL_IND(ht, _val) \
     752             :         ZEND_HASH_REVERSE_FOREACH(ht, 1); \
     753             :         _val = _z;
     754             : 
     755             : #define ZEND_HASH_REVERSE_FOREACH_KEY_VAL(ht, _h, _key, _val) \
     756             :         ZEND_HASH_REVERSE_FOREACH(ht, 0); \
     757             :         _h = _p->h; \
     758             :         _key = _p->key; \
     759             :         _val = _z;
     760             : 
     761             : #define ZEND_HASH_REVERSE_FOREACH_KEY_VAL_IND(ht, _h, _key, _val) \
     762             :         ZEND_HASH_REVERSE_FOREACH(ht, 1); \
     763             :         _h = _p->h; \
     764             :         _key = _p->key; \
     765             :         _val = _z;
     766             : 
     767             : #define ZEND_HASH_APPLY_PROTECTION(ht) \
     768             :         ((ht)->u.flags & HASH_FLAG_APPLY_PROTECTION)
     769             : 
     770             : #define ZEND_HASH_APPLY_SHIFT 8
     771             : #define ZEND_HASH_GET_APPLY_COUNT(ht) ((ht)->u.flags >> ZEND_HASH_APPLY_SHIFT)
     772             : #define ZEND_HASH_INC_APPLY_COUNT(ht) ((ht)->u.flags += (1 << ZEND_HASH_APPLY_SHIFT))
     773             : #define ZEND_HASH_DEC_APPLY_COUNT(ht) ((ht)->u.flags -= (1 << ZEND_HASH_APPLY_SHIFT))
     774             : 
     775             : 
     776             : /* The following macros are useful to insert a sequence of new elements
     777             :  * of packed array. They may be use insted of series of
     778             :  * zend_hash_next_index_insert_new()
     779             :  * (HashTable must have enough free buckets).
     780             :  */
     781             : #define ZEND_HASH_FILL_PACKED(ht) do { \
     782             :                 HashTable *__fill_ht = (ht); \
     783             :                 Bucket *__fill_bkt = __fill_ht->arData + __fill_ht->nNumUsed; \
     784             :                 uint32_t __fill_idx = __fill_ht->nNumUsed; \
     785             :                 ZEND_ASSERT(__fill_ht->u.flags & HASH_FLAG_PACKED);
     786             : 
     787             : #define ZEND_HASH_FILL_ADD(_val) do { \
     788             :                 ZVAL_COPY_VALUE(&__fill_bkt->val, _val); \
     789             :                 __fill_bkt->h = (__fill_idx); \
     790             :                 __fill_bkt->key = NULL; \
     791             :                 __fill_bkt++; \
     792             :                 __fill_idx++; \
     793             :         } while (0)
     794             : 
     795             : #define ZEND_HASH_FILL_END() \
     796             :                 __fill_ht->nNumUsed = __fill_idx; \
     797             :                 __fill_ht->nNumOfElements = __fill_idx; \
     798             :                 __fill_ht->nNextFreeElement = __fill_idx + 1; \
     799             :                 __fill_ht->nInternalPointer = 0; \
     800             :         } while (0)
     801             : 
     802             : #endif                                                  /* ZEND_HASH_H */
     803             : 
     804             : /*
     805             :  * Local variables:
     806             :  * tab-width: 4
     807             :  * c-basic-offset: 4
     808             :  * indent-tabs-mode: t
     809             :  * End:
     810             :  */

Generated by: LCOV version 1.10

Generated at Sun, 01 Mar 2015 23:22:21 +0000 (3 days ago)

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