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

Generated by: LCOV version 1.10

Generated at Mon, 26 Jan 2015 14:46:40 +0000 (1 hour ago)

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