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

LCOV - code coverage report
Current view: top level - Zend - zend_hash.h (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 101 106 95.3 %
Date: 2014-12-13 Functions: 0 0 -
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Sat, 13 Dec 2014 06:16:09 +0000 (8 days ago)

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