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

Generated by: LCOV version 1.10

Generated at Fri, 19 Sep 2014 17:11:04 +0000 (2 hours ago)

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