1 /*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1998-2017 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 | Dmitry Stogov <dmitry@zend.com> |
18 +----------------------------------------------------------------------+
19 */
20
21 /* $Id$ */
22
23 #ifndef ZEND_HASH_H
24 #define ZEND_HASH_H
25
26 #include "zend.h"
27
28 #define HASH_KEY_IS_STRING 1
29 #define HASH_KEY_IS_LONG 2
30 #define HASH_KEY_NON_EXISTENT 3
31
32 #define HASH_UPDATE (1<<0)
33 #define HASH_ADD (1<<1)
34 #define HASH_UPDATE_INDIRECT (1<<2)
35 #define HASH_ADD_NEW (1<<3)
36 #define HASH_ADD_NEXT (1<<4)
37
38 #define HASH_FLAG_PERSISTENT (1<<0)
39 #define HASH_FLAG_APPLY_PROTECTION (1<<1)
40 #define HASH_FLAG_PACKED (1<<2)
41 #define HASH_FLAG_INITIALIZED (1<<3)
42 #define HASH_FLAG_STATIC_KEYS (1<<4)
43 #define HASH_FLAG_HAS_EMPTY_IND (1<<5)
44
45 #define HASH_MASK_CONSISTENCY 0xc0
46
47 typedef struct _zend_hash_key {
48 zend_ulong h;
49 zend_string *key;
50 } zend_hash_key;
51
52 typedef zend_bool (*merge_checker_func_t)(HashTable *target_ht, zval *source_data, zend_hash_key *hash_key, void *pParam);
53
54 BEGIN_EXTERN_C()
55
56 /* startup/shutdown */
57 ZEND_API void ZEND_FASTCALL _zend_hash_init(HashTable *ht, uint32_t nSize, dtor_func_t pDestructor, zend_bool persistent ZEND_FILE_LINE_DC);
58 ZEND_API void ZEND_FASTCALL _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_FASTCALL zend_hash_destroy(HashTable *ht);
60 ZEND_API void ZEND_FASTCALL 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_FASTCALL zend_hash_real_init(HashTable *ht, zend_bool packed);
65 ZEND_API void ZEND_FASTCALL zend_hash_packed_to_hash(HashTable *ht);
66 ZEND_API void ZEND_FASTCALL zend_hash_to_packed(HashTable *ht);
67 ZEND_API void ZEND_FASTCALL zend_hash_extend(HashTable *ht, uint32_t nSize, zend_bool packed);
68
69 /* additions/updates/changes */
70 ZEND_API zval* ZEND_FASTCALL _zend_hash_add_or_update(HashTable *ht, zend_string *key, zval *pData, uint32_t flag ZEND_FILE_LINE_DC);
71 ZEND_API zval* ZEND_FASTCALL _zend_hash_update(HashTable *ht, zend_string *key,zval *pData ZEND_FILE_LINE_DC);
72 ZEND_API zval* ZEND_FASTCALL _zend_hash_update_ind(HashTable *ht, zend_string *key,zval *pData ZEND_FILE_LINE_DC);
73 ZEND_API zval* ZEND_FASTCALL _zend_hash_add(HashTable *ht, zend_string *key,zval *pData ZEND_FILE_LINE_DC);
74 ZEND_API zval* ZEND_FASTCALL _zend_hash_add_new(HashTable *ht, zend_string *key,zval *pData ZEND_FILE_LINE_DC);
75
76 #define zend_hash_update(ht, key, pData) \
77 _zend_hash_update(ht, key, pData ZEND_FILE_LINE_CC)
78 #define zend_hash_update_ind(ht, key, pData) \
79 _zend_hash_update_ind(ht, key, pData ZEND_FILE_LINE_CC)
80 #define zend_hash_add(ht, key, pData) \
81 _zend_hash_add(ht, key, pData ZEND_FILE_LINE_CC)
82 #define zend_hash_add_new(ht, key, pData) \
83 _zend_hash_add_new(ht, key, pData ZEND_FILE_LINE_CC)
84
85 ZEND_API zval* ZEND_FASTCALL _zend_hash_str_add_or_update(HashTable *ht, const char *key, size_t len, zval *pData, uint32_t flag ZEND_FILE_LINE_DC);
86 ZEND_API zval* ZEND_FASTCALL _zend_hash_str_update(HashTable *ht, const char *key, size_t len, zval *pData ZEND_FILE_LINE_DC);
87 ZEND_API zval* ZEND_FASTCALL _zend_hash_str_update_ind(HashTable *ht, const char *key, size_t len, zval *pData ZEND_FILE_LINE_DC);
88 ZEND_API zval* ZEND_FASTCALL _zend_hash_str_add(HashTable *ht, const char *key, size_t len, zval *pData ZEND_FILE_LINE_DC);
89 ZEND_API zval* ZEND_FASTCALL _zend_hash_str_add_new(HashTable *ht, const char *key, size_t len, zval *pData ZEND_FILE_LINE_DC);
90
91 #define zend_hash_str_update(ht, key, len, pData) \
92 _zend_hash_str_update(ht, key, len, pData ZEND_FILE_LINE_CC)
93 #define zend_hash_str_update_ind(ht, key, len, pData) \
94 _zend_hash_str_update_ind(ht, key, len, pData ZEND_FILE_LINE_CC)
95 #define zend_hash_str_add(ht, key, len, pData) \
96 _zend_hash_str_add(ht, key, len, pData ZEND_FILE_LINE_CC)
97 #define zend_hash_str_add_new(ht, key, len, pData) \
98 _zend_hash_str_add_new(ht, key, len, pData ZEND_FILE_LINE_CC)
99
100 ZEND_API zval* ZEND_FASTCALL _zend_hash_index_add_or_update(HashTable *ht, zend_ulong h, zval *pData, uint32_t flag ZEND_FILE_LINE_DC);
101 ZEND_API zval* ZEND_FASTCALL _zend_hash_index_add(HashTable *ht, zend_ulong h, zval *pData ZEND_FILE_LINE_DC);
102 ZEND_API zval* ZEND_FASTCALL _zend_hash_index_add_new(HashTable *ht, zend_ulong h, zval *pData ZEND_FILE_LINE_DC);
103 ZEND_API zval* ZEND_FASTCALL _zend_hash_index_update(HashTable *ht, zend_ulong h, zval *pData ZEND_FILE_LINE_DC);
104 ZEND_API zval* ZEND_FASTCALL _zend_hash_next_index_insert(HashTable *ht, zval *pData ZEND_FILE_LINE_DC);
105 ZEND_API zval* ZEND_FASTCALL _zend_hash_next_index_insert_new(HashTable *ht, zval *pData ZEND_FILE_LINE_DC);
106
107 #define zend_hash_index_add(ht, h, pData) \
108 _zend_hash_index_add(ht, h, pData ZEND_FILE_LINE_CC)
109 #define zend_hash_index_add_new(ht, h, pData) \
110 _zend_hash_index_add_new(ht, h, pData ZEND_FILE_LINE_CC)
111 #define zend_hash_index_update(ht, h, pData) \
112 _zend_hash_index_update(ht, h, pData ZEND_FILE_LINE_CC)
113 #define zend_hash_next_index_insert(ht, pData) \
114 _zend_hash_next_index_insert(ht, pData ZEND_FILE_LINE_CC)
115 #define zend_hash_next_index_insert_new(ht, pData) \
116 _zend_hash_next_index_insert_new(ht, pData ZEND_FILE_LINE_CC)
117
118 ZEND_API zval* ZEND_FASTCALL zend_hash_index_add_empty_element(HashTable *ht, zend_ulong h);
119 ZEND_API zval* ZEND_FASTCALL zend_hash_add_empty_element(HashTable *ht, zend_string *key);
120 ZEND_API zval* ZEND_FASTCALL zend_hash_str_add_empty_element(HashTable *ht, const char *key, size_t len);
121
122 #define ZEND_HASH_APPLY_KEEP 0
123 #define ZEND_HASH_APPLY_REMOVE 1<<0
124 #define ZEND_HASH_APPLY_STOP 1<<1
125
126 typedef int (*apply_func_t)(zval *pDest);
127 typedef int (*apply_func_arg_t)(zval *pDest, void *argument);
128 typedef int (*apply_func_args_t)(zval *pDest, int num_args, va_list args, zend_hash_key *hash_key);
129
130 ZEND_API void ZEND_FASTCALL zend_hash_graceful_destroy(HashTable *ht);
131 ZEND_API void ZEND_FASTCALL zend_hash_graceful_reverse_destroy(HashTable *ht);
132 ZEND_API void ZEND_FASTCALL zend_hash_apply(HashTable *ht, apply_func_t apply_func);
133 ZEND_API void ZEND_FASTCALL zend_hash_apply_with_argument(HashTable *ht, apply_func_arg_t apply_func, void *);
134 ZEND_API void ZEND_FASTCALL zend_hash_apply_with_arguments(HashTable *ht, apply_func_args_t apply_func, int, ...);
135
136 /* This function should be used with special care (in other words,
137 * it should usually not be used). When used with the ZEND_HASH_APPLY_STOP
138 * return value, it assumes things about the order of the elements in the hash.
139 * Also, it does not provide the same kind of reentrancy protection that
140 * the standard apply functions do.
141 */
142 ZEND_API void ZEND_FASTCALL zend_hash_reverse_apply(HashTable *ht, apply_func_t apply_func);
143
144
145 /* Deletes */
146 ZEND_API int ZEND_FASTCALL zend_hash_del(HashTable *ht, zend_string *key);
147 ZEND_API int ZEND_FASTCALL zend_hash_del_ind(HashTable *ht, zend_string *key);
148 ZEND_API int ZEND_FASTCALL zend_hash_str_del(HashTable *ht, const char *key, size_t len);
149 ZEND_API int ZEND_FASTCALL zend_hash_str_del_ind(HashTable *ht, const char *key, size_t len);
150 ZEND_API int ZEND_FASTCALL zend_hash_index_del(HashTable *ht, zend_ulong h);
151 ZEND_API void ZEND_FASTCALL zend_hash_del_bucket(HashTable *ht, Bucket *p);
152
153 /* Data retreival */
154 ZEND_API zval* ZEND_FASTCALL zend_hash_find(const HashTable *ht, zend_string *key);
155 ZEND_API zval* ZEND_FASTCALL zend_hash_str_find(const HashTable *ht, const char *key, size_t len);
156 ZEND_API zval* ZEND_FASTCALL zend_hash_index_find(const HashTable *ht, zend_ulong h);
157
158 /* Misc */
159 ZEND_API zend_bool ZEND_FASTCALL zend_hash_exists(const HashTable *ht, zend_string *key);
160 ZEND_API zend_bool ZEND_FASTCALL zend_hash_str_exists(const HashTable *ht, const char *str, size_t len);
161 ZEND_API zend_bool ZEND_FASTCALL zend_hash_index_exists(const HashTable *ht, zend_ulong h);
162
163 /* traversing */
164 #define zend_hash_has_more_elements_ex(ht, pos) \
165 (zend_hash_get_current_key_type_ex(ht, pos) == HASH_KEY_NON_EXISTENT ? FAILURE : SUCCESS)
166 ZEND_API int ZEND_FASTCALL zend_hash_move_forward_ex(HashTable *ht, HashPosition *pos);
167 ZEND_API int ZEND_FASTCALL zend_hash_move_backwards_ex(HashTable *ht, HashPosition *pos);
168 ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_ex(const HashTable *ht, zend_string **str_index, zend_ulong *num_index, HashPosition *pos);
169 ZEND_API void ZEND_FASTCALL zend_hash_get_current_key_zval_ex(const HashTable *ht, zval *key, HashPosition *pos);
170 ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_type_ex(HashTable *ht, HashPosition *pos);
171 ZEND_API zval* ZEND_FASTCALL zend_hash_get_current_data_ex(HashTable *ht, HashPosition *pos);
172 ZEND_API void ZEND_FASTCALL zend_hash_internal_pointer_reset_ex(HashTable *ht, HashPosition *pos);
173 ZEND_API void ZEND_FASTCALL zend_hash_internal_pointer_end_ex(HashTable *ht, HashPosition *pos);
174
175 #define zend_hash_has_more_elements(ht) \
176 zend_hash_has_more_elements_ex(ht, &(ht)->nInternalPointer)
177 #define zend_hash_move_forward(ht) \
178 zend_hash_move_forward_ex(ht, &(ht)->nInternalPointer)
179 #define zend_hash_move_backwards(ht) \
180 zend_hash_move_backwards_ex(ht, &(ht)->nInternalPointer)
181 #define zend_hash_get_current_key(ht, str_index, num_index) \
182 zend_hash_get_current_key_ex(ht, str_index, num_index, &(ht)->nInternalPointer)
183 #define zend_hash_get_current_key_zval(ht, key) \
184 zend_hash_get_current_key_zval_ex(ht, key, &(ht)->nInternalPointer)
185 #define zend_hash_get_current_key_type(ht) \
186 zend_hash_get_current_key_type_ex(ht, &(ht)->nInternalPointer)
187 #define zend_hash_get_current_data(ht) \
188 zend_hash_get_current_data_ex(ht, &(ht)->nInternalPointer)
189 #define zend_hash_internal_pointer_reset(ht) \
190 zend_hash_internal_pointer_reset_ex(ht, &(ht)->nInternalPointer)
191 #define zend_hash_internal_pointer_end(ht) \
192 zend_hash_internal_pointer_end_ex(ht, &(ht)->nInternalPointer)
193
194 /* Copying, merging and sorting */
195 ZEND_API void ZEND_FASTCALL zend_hash_copy(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor);
196 ZEND_API void ZEND_FASTCALL _zend_hash_merge(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, zend_bool overwrite ZEND_FILE_LINE_DC);
197 ZEND_API void ZEND_FASTCALL zend_hash_merge_ex(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, merge_checker_func_t pMergeSource, void *pParam);
198 ZEND_API void zend_hash_bucket_swap(Bucket *p, Bucket *q);
199 ZEND_API void zend_hash_bucket_renum_swap(Bucket *p, Bucket *q);
200 ZEND_API void zend_hash_bucket_packed_swap(Bucket *p, Bucket *q);
201 ZEND_API int zend_hash_compare(HashTable *ht1, HashTable *ht2, compare_func_t compar, zend_bool ordered);
202 ZEND_API int ZEND_FASTCALL zend_hash_sort_ex(HashTable *ht, sort_func_t sort_func, compare_func_t compare_func, zend_bool renumber);
203 ZEND_API zval* ZEND_FASTCALL zend_hash_minmax(const HashTable *ht, compare_func_t compar, uint32_t flag);
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_sort(ht, compare_func, renumber) \
209 zend_hash_sort_ex(ht, zend_sort, compare_func, renumber)
210
211 #define zend_hash_num_elements(ht) \
212 (ht)->nNumOfElements
213
214 #define zend_hash_next_free_element(ht) \
215 (ht)->nNextFreeElement
216
217 ZEND_API int ZEND_FASTCALL zend_hash_rehash(HashTable *ht);
218
219 ZEND_API uint32_t zend_array_count(HashTable *ht);
220 ZEND_API HashTable* ZEND_FASTCALL zend_array_dup(HashTable *source);
221 ZEND_API void ZEND_FASTCALL zend_array_destroy(HashTable *ht);
222 ZEND_API void ZEND_FASTCALL zend_symtable_clean(HashTable *ht);
223
224 ZEND_API int ZEND_FASTCALL _zend_handle_numeric_str_ex(const char *key, size_t length, zend_ulong *idx);
225
226 ZEND_API uint32_t ZEND_FASTCALL zend_hash_iterator_add(HashTable *ht, HashPosition pos);
227 ZEND_API HashPosition ZEND_FASTCALL zend_hash_iterator_pos(uint32_t idx, HashTable *ht);
228 ZEND_API HashPosition ZEND_FASTCALL zend_hash_iterator_pos_ex(uint32_t idx, zval *array);
229 ZEND_API void ZEND_FASTCALL zend_hash_iterator_del(uint32_t idx);
230 ZEND_API HashPosition ZEND_FASTCALL zend_hash_iterators_lower_pos(HashTable *ht, HashPosition start);
231 ZEND_API void ZEND_FASTCALL _zend_hash_iterators_update(HashTable *ht, HashPosition from, HashPosition to);
232
zend_hash_iterators_update(HashTable * ht,HashPosition from,HashPosition to)233 static zend_always_inline void zend_hash_iterators_update(HashTable *ht, HashPosition from, HashPosition to)
234 {
235 if (UNEXPECTED(ht->u.v.nIteratorsCount)) {
236 _zend_hash_iterators_update(ht, from, to);
237 }
238 }
239
240
END_EXTERN_C()241 END_EXTERN_C()
242
243 #define ZEND_INIT_SYMTABLE(ht) \
244 ZEND_INIT_SYMTABLE_EX(ht, 8, 0)
245
246 #define ZEND_INIT_SYMTABLE_EX(ht, n, persistent) \
247 zend_hash_init(ht, n, NULL, ZVAL_PTR_DTOR, persistent)
248
249 static zend_always_inline int _zend_handle_numeric_str(const char *key, size_t length, zend_ulong *idx)
250 {
251 register const char *tmp = key;
252
253 if (*tmp > '9') {
254 return 0;
255 } else if (*tmp < '0') {
256 if (*tmp != '-') {
257 return 0;
258 }
259 tmp++;
260 if (*tmp > '9' || *tmp < '0') {
261 return 0;
262 }
263 }
264 return _zend_handle_numeric_str_ex(key, length, idx);
265 }
266
267 #define ZEND_HANDLE_NUMERIC_STR(key, length, idx) \
268 _zend_handle_numeric_str(key, length, &idx)
269
270 #define ZEND_HANDLE_NUMERIC(key, idx) \
271 ZEND_HANDLE_NUMERIC_STR(ZSTR_VAL(key), ZSTR_LEN(key), idx)
272
273
zend_hash_find_ind(const HashTable * ht,zend_string * key)274 static zend_always_inline zval *zend_hash_find_ind(const HashTable *ht, zend_string *key)
275 {
276 zval *zv;
277
278 zv = zend_hash_find(ht, key);
279 return (zv && Z_TYPE_P(zv) == IS_INDIRECT) ?
280 ((Z_TYPE_P(Z_INDIRECT_P(zv)) != IS_UNDEF) ? Z_INDIRECT_P(zv) : NULL) : zv;
281 }
282
283
zend_hash_exists_ind(const HashTable * ht,zend_string * key)284 static zend_always_inline int zend_hash_exists_ind(const HashTable *ht, zend_string *key)
285 {
286 zval *zv;
287
288 zv = zend_hash_find(ht, key);
289 return zv && (Z_TYPE_P(zv) != IS_INDIRECT ||
290 Z_TYPE_P(Z_INDIRECT_P(zv)) != IS_UNDEF);
291 }
292
293
zend_hash_str_find_ind(const HashTable * ht,const char * str,size_t len)294 static zend_always_inline zval *zend_hash_str_find_ind(const HashTable *ht, const char *str, size_t len)
295 {
296 zval *zv;
297
298 zv = zend_hash_str_find(ht, str, len);
299 return (zv && Z_TYPE_P(zv) == IS_INDIRECT) ?
300 ((Z_TYPE_P(Z_INDIRECT_P(zv)) != IS_UNDEF) ? Z_INDIRECT_P(zv) : NULL) : zv;
301 }
302
303
zend_hash_str_exists_ind(const HashTable * ht,const char * str,size_t len)304 static zend_always_inline int zend_hash_str_exists_ind(const HashTable *ht, const char *str, size_t len)
305 {
306 zval *zv;
307
308 zv = zend_hash_str_find(ht, str, len);
309 return zv && (Z_TYPE_P(zv) != IS_INDIRECT ||
310 Z_TYPE_P(Z_INDIRECT_P(zv)) != IS_UNDEF);
311 }
312
zend_symtable_add_new(HashTable * ht,zend_string * key,zval * pData)313 static zend_always_inline zval *zend_symtable_add_new(HashTable *ht, zend_string *key, zval *pData)
314 {
315 zend_ulong idx;
316
317 if (ZEND_HANDLE_NUMERIC(key, idx)) {
318 return zend_hash_index_add_new(ht, idx, pData);
319 } else {
320 return zend_hash_add_new(ht, key, pData);
321 }
322 }
323
324 /* This typo snuck into 7.0.17 and 7.1.3, this define exists for BC */
325 #define zend_symbtable_add_new(ht, key, pData) \
326 zend_symtable_add_new(ht, key, pData)
327
zend_symtable_update(HashTable * ht,zend_string * key,zval * pData)328 static zend_always_inline zval *zend_symtable_update(HashTable *ht, zend_string *key, zval *pData)
329 {
330 zend_ulong idx;
331
332 if (ZEND_HANDLE_NUMERIC(key, idx)) {
333 return zend_hash_index_update(ht, idx, pData);
334 } else {
335 return zend_hash_update(ht, key, pData);
336 }
337 }
338
339
zend_symtable_update_ind(HashTable * ht,zend_string * key,zval * pData)340 static zend_always_inline zval *zend_symtable_update_ind(HashTable *ht, zend_string *key, zval *pData)
341 {
342 zend_ulong idx;
343
344 if (ZEND_HANDLE_NUMERIC(key, idx)) {
345 return zend_hash_index_update(ht, idx, pData);
346 } else {
347 return zend_hash_update_ind(ht, key, pData);
348 }
349 }
350
351
zend_symtable_del(HashTable * ht,zend_string * key)352 static zend_always_inline int zend_symtable_del(HashTable *ht, zend_string *key)
353 {
354 zend_ulong idx;
355
356 if (ZEND_HANDLE_NUMERIC(key, idx)) {
357 return zend_hash_index_del(ht, idx);
358 } else {
359 return zend_hash_del(ht, key);
360 }
361 }
362
363
zend_symtable_del_ind(HashTable * ht,zend_string * key)364 static zend_always_inline int zend_symtable_del_ind(HashTable *ht, zend_string *key)
365 {
366 zend_ulong idx;
367
368 if (ZEND_HANDLE_NUMERIC(key, idx)) {
369 return zend_hash_index_del(ht, idx);
370 } else {
371 return zend_hash_del_ind(ht, key);
372 }
373 }
374
375
zend_symtable_find(const HashTable * ht,zend_string * key)376 static zend_always_inline zval *zend_symtable_find(const HashTable *ht, zend_string *key)
377 {
378 zend_ulong idx;
379
380 if (ZEND_HANDLE_NUMERIC(key, idx)) {
381 return zend_hash_index_find(ht, idx);
382 } else {
383 return zend_hash_find(ht, key);
384 }
385 }
386
387
zend_symtable_find_ind(const HashTable * ht,zend_string * key)388 static zend_always_inline zval *zend_symtable_find_ind(const HashTable *ht, zend_string *key)
389 {
390 zend_ulong idx;
391
392 if (ZEND_HANDLE_NUMERIC(key, idx)) {
393 return zend_hash_index_find(ht, idx);
394 } else {
395 return zend_hash_find_ind(ht, key);
396 }
397 }
398
399
zend_symtable_exists(HashTable * ht,zend_string * key)400 static zend_always_inline int zend_symtable_exists(HashTable *ht, zend_string *key)
401 {
402 zend_ulong idx;
403
404 if (ZEND_HANDLE_NUMERIC(key, idx)) {
405 return zend_hash_index_exists(ht, idx);
406 } else {
407 return zend_hash_exists(ht, key);
408 }
409 }
410
411
zend_symtable_exists_ind(HashTable * ht,zend_string * key)412 static zend_always_inline int zend_symtable_exists_ind(HashTable *ht, zend_string *key)
413 {
414 zend_ulong idx;
415
416 if (ZEND_HANDLE_NUMERIC(key, idx)) {
417 return zend_hash_index_exists(ht, idx);
418 } else {
419 return zend_hash_exists_ind(ht, key);
420 }
421 }
422
423
zend_symtable_str_update(HashTable * ht,const char * str,size_t len,zval * pData)424 static zend_always_inline zval *zend_symtable_str_update(HashTable *ht, const char *str, size_t len, zval *pData)
425 {
426 zend_ulong idx;
427
428 if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
429 return zend_hash_index_update(ht, idx, pData);
430 } else {
431 return zend_hash_str_update(ht, str, len, pData);
432 }
433 }
434
435
zend_symtable_str_update_ind(HashTable * ht,const char * str,size_t len,zval * pData)436 static zend_always_inline zval *zend_symtable_str_update_ind(HashTable *ht, const char *str, size_t len, zval *pData)
437 {
438 zend_ulong idx;
439
440 if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
441 return zend_hash_index_update(ht, idx, pData);
442 } else {
443 return zend_hash_str_update_ind(ht, str, len, pData);
444 }
445 }
446
447
zend_symtable_str_del(HashTable * ht,const char * str,size_t len)448 static zend_always_inline int zend_symtable_str_del(HashTable *ht, const char *str, size_t len)
449 {
450 zend_ulong idx;
451
452 if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
453 return zend_hash_index_del(ht, idx);
454 } else {
455 return zend_hash_str_del(ht, str, len);
456 }
457 }
458
459
zend_symtable_str_del_ind(HashTable * ht,const char * str,size_t len)460 static zend_always_inline int zend_symtable_str_del_ind(HashTable *ht, const char *str, size_t len)
461 {
462 zend_ulong idx;
463
464 if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
465 return zend_hash_index_del(ht, idx);
466 } else {
467 return zend_hash_str_del_ind(ht, str, len);
468 }
469 }
470
471
zend_symtable_str_find(HashTable * ht,const char * str,size_t len)472 static zend_always_inline zval *zend_symtable_str_find(HashTable *ht, const char *str, size_t len)
473 {
474 zend_ulong idx;
475
476 if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
477 return zend_hash_index_find(ht, idx);
478 } else {
479 return zend_hash_str_find(ht, str, len);
480 }
481 }
482
483
zend_symtable_str_exists(HashTable * ht,const char * str,size_t len)484 static zend_always_inline int zend_symtable_str_exists(HashTable *ht, const char *str, size_t len)
485 {
486 zend_ulong idx;
487
488 if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
489 return zend_hash_index_exists(ht, idx);
490 } else {
491 return zend_hash_str_exists(ht, str, len);
492 }
493 }
494
zend_hash_add_ptr(HashTable * ht,zend_string * key,void * pData)495 static zend_always_inline void *zend_hash_add_ptr(HashTable *ht, zend_string *key, void *pData)
496 {
497 zval tmp, *zv;
498
499 ZVAL_PTR(&tmp, pData);
500 zv = zend_hash_add(ht, key, &tmp);
501 if (zv) {
502 ZEND_ASSUME(Z_PTR_P(zv));
503 return Z_PTR_P(zv);
504 } else {
505 return NULL;
506 }
507 }
508
zend_hash_add_new_ptr(HashTable * ht,zend_string * key,void * pData)509 static zend_always_inline void *zend_hash_add_new_ptr(HashTable *ht, zend_string *key, void *pData)
510 {
511 zval tmp, *zv;
512
513 ZVAL_PTR(&tmp, pData);
514 zv = zend_hash_add_new(ht, key, &tmp);
515 if (zv) {
516 ZEND_ASSUME(Z_PTR_P(zv));
517 return Z_PTR_P(zv);
518 } else {
519 return NULL;
520 }
521 }
522
zend_hash_str_add_ptr(HashTable * ht,const char * str,size_t len,void * pData)523 static zend_always_inline void *zend_hash_str_add_ptr(HashTable *ht, const char *str, size_t len, void *pData)
524 {
525 zval tmp, *zv;
526
527 ZVAL_PTR(&tmp, pData);
528 zv = zend_hash_str_add(ht, str, len, &tmp);
529 if (zv) {
530 ZEND_ASSUME(Z_PTR_P(zv));
531 return Z_PTR_P(zv);
532 } else {
533 return NULL;
534 }
535 }
536
zend_hash_str_add_new_ptr(HashTable * ht,const char * str,size_t len,void * pData)537 static zend_always_inline void *zend_hash_str_add_new_ptr(HashTable *ht, const char *str, size_t len, void *pData)
538 {
539 zval tmp, *zv;
540
541 ZVAL_PTR(&tmp, pData);
542 zv = zend_hash_str_add_new(ht, str, len, &tmp);
543 if (zv) {
544 ZEND_ASSUME(Z_PTR_P(zv));
545 return Z_PTR_P(zv);
546 } else {
547 return NULL;
548 }
549 }
550
zend_hash_update_ptr(HashTable * ht,zend_string * key,void * pData)551 static zend_always_inline void *zend_hash_update_ptr(HashTable *ht, zend_string *key, void *pData)
552 {
553 zval tmp, *zv;
554
555 ZVAL_PTR(&tmp, pData);
556 zv = zend_hash_update(ht, key, &tmp);
557 if (zv) {
558 ZEND_ASSUME(Z_PTR_P(zv));
559 return Z_PTR_P(zv);
560 } else {
561 return NULL;
562 }
563 }
564
zend_hash_str_update_ptr(HashTable * ht,const char * str,size_t len,void * pData)565 static zend_always_inline void *zend_hash_str_update_ptr(HashTable *ht, const char *str, size_t len, void *pData)
566 {
567 zval tmp, *zv;
568
569 ZVAL_PTR(&tmp, pData);
570 zv = zend_hash_str_update(ht, str, len, &tmp);
571 if (zv) {
572 ZEND_ASSUME(Z_PTR_P(zv));
573 return Z_PTR_P(zv);
574 } else {
575 return NULL;
576 }
577 }
578
zend_hash_add_mem(HashTable * ht,zend_string * key,void * pData,size_t size)579 static zend_always_inline void *zend_hash_add_mem(HashTable *ht, zend_string *key, void *pData, size_t size)
580 {
581 zval tmp, *zv;
582
583 ZVAL_PTR(&tmp, NULL);
584 if ((zv = zend_hash_add(ht, key, &tmp))) {
585 Z_PTR_P(zv) = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
586 memcpy(Z_PTR_P(zv), pData, size);
587 return Z_PTR_P(zv);
588 }
589 return NULL;
590 }
591
zend_hash_str_add_mem(HashTable * ht,const char * str,size_t len,void * pData,size_t size)592 static zend_always_inline void *zend_hash_str_add_mem(HashTable *ht, const char *str, size_t len, void *pData, size_t size)
593 {
594 zval tmp, *zv;
595
596 ZVAL_PTR(&tmp, NULL);
597 if ((zv = zend_hash_str_add(ht, str, len, &tmp))) {
598 Z_PTR_P(zv) = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
599 memcpy(Z_PTR_P(zv), pData, size);
600 return Z_PTR_P(zv);
601 }
602 return NULL;
603 }
604
zend_hash_update_mem(HashTable * ht,zend_string * key,void * pData,size_t size)605 static zend_always_inline void *zend_hash_update_mem(HashTable *ht, zend_string *key, void *pData, size_t size)
606 {
607 void *p;
608
609 p = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
610 memcpy(p, pData, size);
611 return zend_hash_update_ptr(ht, key, p);
612 }
613
zend_hash_str_update_mem(HashTable * ht,const char * str,size_t len,void * pData,size_t size)614 static zend_always_inline void *zend_hash_str_update_mem(HashTable *ht, const char *str, size_t len, void *pData, size_t size)
615 {
616 void *p;
617
618 p = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
619 memcpy(p, pData, size);
620 return zend_hash_str_update_ptr(ht, str, len, p);
621 }
622
zend_hash_index_add_ptr(HashTable * ht,zend_ulong h,void * pData)623 static zend_always_inline void *zend_hash_index_add_ptr(HashTable *ht, zend_ulong h, void *pData)
624 {
625 zval tmp, *zv;
626
627 ZVAL_PTR(&tmp, pData);
628 zv = zend_hash_index_add(ht, h, &tmp);
629 return zv ? Z_PTR_P(zv) : NULL;
630 }
631
zend_hash_index_add_new_ptr(HashTable * ht,zend_ulong h,void * pData)632 static zend_always_inline void *zend_hash_index_add_new_ptr(HashTable *ht, zend_ulong h, void *pData)
633 {
634 zval tmp, *zv;
635
636 ZVAL_PTR(&tmp, pData);
637 zv = zend_hash_index_add_new(ht, h, &tmp);
638 return zv ? Z_PTR_P(zv) : NULL;
639 }
640
zend_hash_index_update_ptr(HashTable * ht,zend_ulong h,void * pData)641 static zend_always_inline void *zend_hash_index_update_ptr(HashTable *ht, zend_ulong h, void *pData)
642 {
643 zval tmp, *zv;
644
645 ZVAL_PTR(&tmp, pData);
646 zv = zend_hash_index_update(ht, h, &tmp);
647 if (zv) {
648 ZEND_ASSUME(Z_PTR_P(zv));
649 return Z_PTR_P(zv);
650 } else {
651 return NULL;
652 }
653 }
654
zend_hash_index_add_mem(HashTable * ht,zend_ulong h,void * pData,size_t size)655 static zend_always_inline void *zend_hash_index_add_mem(HashTable *ht, zend_ulong h, void *pData, size_t size)
656 {
657 zval tmp, *zv;
658
659 ZVAL_PTR(&tmp, NULL);
660 if ((zv = zend_hash_index_add(ht, h, &tmp))) {
661 Z_PTR_P(zv) = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
662 memcpy(Z_PTR_P(zv), pData, size);
663 return Z_PTR_P(zv);
664 }
665 return NULL;
666 }
667
zend_hash_next_index_insert_ptr(HashTable * ht,void * pData)668 static zend_always_inline void *zend_hash_next_index_insert_ptr(HashTable *ht, void *pData)
669 {
670 zval tmp, *zv;
671
672 ZVAL_PTR(&tmp, pData);
673 zv = zend_hash_next_index_insert(ht, &tmp);
674 if (zv) {
675 ZEND_ASSUME(Z_PTR_P(zv));
676 return Z_PTR_P(zv);
677 } else {
678 return NULL;
679 }
680 }
681
zend_hash_index_update_mem(HashTable * ht,zend_ulong h,void * pData,size_t size)682 static zend_always_inline void *zend_hash_index_update_mem(HashTable *ht, zend_ulong h, void *pData, size_t size)
683 {
684 void *p;
685
686 p = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
687 memcpy(p, pData, size);
688 return zend_hash_index_update_ptr(ht, h, p);
689 }
690
zend_hash_next_index_insert_mem(HashTable * ht,void * pData,size_t size)691 static zend_always_inline void *zend_hash_next_index_insert_mem(HashTable *ht, void *pData, size_t size)
692 {
693 zval tmp, *zv;
694
695 ZVAL_PTR(&tmp, NULL);
696 if ((zv = zend_hash_next_index_insert(ht, &tmp))) {
697 Z_PTR_P(zv) = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
698 memcpy(Z_PTR_P(zv), pData, size);
699 return Z_PTR_P(zv);
700 }
701 return NULL;
702 }
703
zend_hash_find_ptr(const HashTable * ht,zend_string * key)704 static zend_always_inline void *zend_hash_find_ptr(const HashTable *ht, zend_string *key)
705 {
706 zval *zv;
707
708 zv = zend_hash_find(ht, key);
709 if (zv) {
710 ZEND_ASSUME(Z_PTR_P(zv));
711 return Z_PTR_P(zv);
712 } else {
713 return NULL;
714 }
715 }
716
zend_hash_str_find_ptr(const HashTable * ht,const char * str,size_t len)717 static zend_always_inline void *zend_hash_str_find_ptr(const HashTable *ht, const char *str, size_t len)
718 {
719 zval *zv;
720
721 zv = zend_hash_str_find(ht, str, len);
722 if (zv) {
723 ZEND_ASSUME(Z_PTR_P(zv));
724 return Z_PTR_P(zv);
725 } else {
726 return NULL;
727 }
728 }
729
zend_hash_index_find_ptr(const HashTable * ht,zend_ulong h)730 static zend_always_inline void *zend_hash_index_find_ptr(const HashTable *ht, zend_ulong h)
731 {
732 zval *zv;
733
734 zv = zend_hash_index_find(ht, h);
735 if (zv) {
736 ZEND_ASSUME(Z_PTR_P(zv));
737 return Z_PTR_P(zv);
738 } else {
739 return NULL;
740 }
741 }
742
zend_symtable_str_find_ptr(HashTable * ht,const char * str,size_t len)743 static zend_always_inline void *zend_symtable_str_find_ptr(HashTable *ht, const char *str, size_t len)
744 {
745 zend_ulong idx;
746
747 if (ZEND_HANDLE_NUMERIC_STR(str, len, idx)) {
748 return zend_hash_index_find_ptr(ht, idx);
749 } else {
750 return zend_hash_str_find_ptr(ht, str, len);
751 }
752 }
753
zend_hash_get_current_data_ptr_ex(HashTable * ht,HashPosition * pos)754 static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, HashPosition *pos)
755 {
756 zval *zv;
757
758 zv = zend_hash_get_current_data_ex(ht, pos);
759 if (zv) {
760 ZEND_ASSUME(Z_PTR_P(zv));
761 return Z_PTR_P(zv);
762 } else {
763 return NULL;
764 }
765 }
766
767 #define zend_hash_get_current_data_ptr(ht) \
768 zend_hash_get_current_data_ptr_ex(ht, &(ht)->nInternalPointer)
769
770 #define ZEND_HASH_FOREACH(_ht, indirect) do { \
771 Bucket *_p = (_ht)->arData; \
772 Bucket *_end = _p + (_ht)->nNumUsed; \
773 for (; _p != _end; _p++) { \
774 zval *_z = &_p->val; \
775 if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \
776 _z = Z_INDIRECT_P(_z); \
777 } \
778 if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue;
779
780 #define ZEND_HASH_REVERSE_FOREACH(_ht, indirect) do { \
781 uint _idx; \
782 for (_idx = (_ht)->nNumUsed; _idx > 0; _idx--) { \
783 Bucket *_p = (_ht)->arData + _idx - 1; \
784 zval *_z = &_p->val; \
785 if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \
786 _z = Z_INDIRECT_P(_z); \
787 } \
788 if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue;
789
790 #define ZEND_HASH_FOREACH_END() \
791 } \
792 } while (0)
793
794 #define ZEND_HASH_FOREACH_BUCKET(ht, _bucket) \
795 ZEND_HASH_FOREACH(ht, 0); \
796 _bucket = _p;
797
798 #define ZEND_HASH_FOREACH_VAL(ht, _val) \
799 ZEND_HASH_FOREACH(ht, 0); \
800 _val = _z;
801
802 #define ZEND_HASH_FOREACH_VAL_IND(ht, _val) \
803 ZEND_HASH_FOREACH(ht, 1); \
804 _val = _z;
805
806 #define ZEND_HASH_FOREACH_PTR(ht, _ptr) \
807 ZEND_HASH_FOREACH(ht, 0); \
808 _ptr = Z_PTR_P(_z);
809
810 #define ZEND_HASH_FOREACH_NUM_KEY(ht, _h) \
811 ZEND_HASH_FOREACH(ht, 0); \
812 _h = _p->h;
813
814 #define ZEND_HASH_FOREACH_STR_KEY(ht, _key) \
815 ZEND_HASH_FOREACH(ht, 0); \
816 _key = _p->key;
817
818 #define ZEND_HASH_FOREACH_KEY(ht, _h, _key) \
819 ZEND_HASH_FOREACH(ht, 0); \
820 _h = _p->h; \
821 _key = _p->key;
822
823 #define ZEND_HASH_FOREACH_NUM_KEY_VAL(ht, _h, _val) \
824 ZEND_HASH_FOREACH(ht, 0); \
825 _h = _p->h; \
826 _val = _z;
827
828 #define ZEND_HASH_FOREACH_STR_KEY_VAL(ht, _key, _val) \
829 ZEND_HASH_FOREACH(ht, 0); \
830 _key = _p->key; \
831 _val = _z;
832
833 #define ZEND_HASH_FOREACH_KEY_VAL(ht, _h, _key, _val) \
834 ZEND_HASH_FOREACH(ht, 0); \
835 _h = _p->h; \
836 _key = _p->key; \
837 _val = _z;
838
839 #define ZEND_HASH_FOREACH_STR_KEY_VAL_IND(ht, _key, _val) \
840 ZEND_HASH_FOREACH(ht, 1); \
841 _key = _p->key; \
842 _val = _z;
843
844 #define ZEND_HASH_FOREACH_KEY_VAL_IND(ht, _h, _key, _val) \
845 ZEND_HASH_FOREACH(ht, 1); \
846 _h = _p->h; \
847 _key = _p->key; \
848 _val = _z;
849
850 #define ZEND_HASH_FOREACH_NUM_KEY_PTR(ht, _h, _ptr) \
851 ZEND_HASH_FOREACH(ht, 0); \
852 _h = _p->h; \
853 _ptr = Z_PTR_P(_z);
854
855 #define ZEND_HASH_FOREACH_STR_KEY_PTR(ht, _key, _ptr) \
856 ZEND_HASH_FOREACH(ht, 0); \
857 _key = _p->key; \
858 _ptr = Z_PTR_P(_z);
859
860 #define ZEND_HASH_FOREACH_KEY_PTR(ht, _h, _key, _ptr) \
861 ZEND_HASH_FOREACH(ht, 0); \
862 _h = _p->h; \
863 _key = _p->key; \
864 _ptr = Z_PTR_P(_z);
865
866 #define ZEND_HASH_REVERSE_FOREACH_BUCKET(ht, _bucket) \
867 ZEND_HASH_REVERSE_FOREACH(ht, 0); \
868 _bucket = _p;
869
870 #define ZEND_HASH_REVERSE_FOREACH_VAL(ht, _val) \
871 ZEND_HASH_REVERSE_FOREACH(ht, 0); \
872 _val = _z;
873
874 #define ZEND_HASH_REVERSE_FOREACH_PTR(ht, _ptr) \
875 ZEND_HASH_REVERSE_FOREACH(ht, 0); \
876 _ptr = Z_PTR_P(_z);
877
878 #define ZEND_HASH_REVERSE_FOREACH_VAL_IND(ht, _val) \
879 ZEND_HASH_REVERSE_FOREACH(ht, 1); \
880 _val = _z;
881
882 #define ZEND_HASH_REVERSE_FOREACH_KEY_VAL(ht, _h, _key, _val) \
883 ZEND_HASH_REVERSE_FOREACH(ht, 0); \
884 _h = _p->h; \
885 _key = _p->key; \
886 _val = _z;
887
888 #define ZEND_HASH_REVERSE_FOREACH_KEY_VAL_IND(ht, _h, _key, _val) \
889 ZEND_HASH_REVERSE_FOREACH(ht, 1); \
890 _h = _p->h; \
891 _key = _p->key; \
892 _val = _z;
893
894 #define ZEND_HASH_APPLY_PROTECTION(ht) \
895 ((ht)->u.flags & HASH_FLAG_APPLY_PROTECTION)
896
897 #define ZEND_HASH_APPLY_SHIFT 8
898 #define ZEND_HASH_APPLY_COUNT_MASK 0xff00
899 #define ZEND_HASH_GET_APPLY_COUNT(ht) (((ht)->u.flags & ZEND_HASH_APPLY_COUNT_MASK) >> ZEND_HASH_APPLY_SHIFT)
900 #define ZEND_HASH_INC_APPLY_COUNT(ht) ((ht)->u.flags += (1 << ZEND_HASH_APPLY_SHIFT))
901 #define ZEND_HASH_DEC_APPLY_COUNT(ht) ((ht)->u.flags -= (1 << ZEND_HASH_APPLY_SHIFT))
902
903
904 /* The following macros are useful to insert a sequence of new elements
905 * of packed array. They may be use insted of series of
906 * zend_hash_next_index_insert_new()
907 * (HashTable must have enough free buckets).
908 */
909 #define ZEND_HASH_FILL_PACKED(ht) do { \
910 HashTable *__fill_ht = (ht); \
911 Bucket *__fill_bkt = __fill_ht->arData + __fill_ht->nNumUsed; \
912 uint32_t __fill_idx = __fill_ht->nNumUsed; \
913 ZEND_ASSERT(__fill_ht->u.flags & HASH_FLAG_PACKED);
914
915 #define ZEND_HASH_FILL_ADD(_val) do { \
916 ZVAL_COPY_VALUE(&__fill_bkt->val, _val); \
917 __fill_bkt->h = (__fill_idx); \
918 __fill_bkt->key = NULL; \
919 __fill_bkt++; \
920 __fill_idx++; \
921 } while (0)
922
923 #define ZEND_HASH_FILL_END() \
924 __fill_ht->nNumUsed = __fill_idx; \
925 __fill_ht->nNumOfElements = __fill_idx; \
926 __fill_ht->nNextFreeElement = __fill_idx; \
927 __fill_ht->nInternalPointer = __fill_idx ? 0 : HT_INVALID_IDX; \
928 } while (0)
929
_zend_hash_append(HashTable * ht,zend_string * key,zval * zv)930 static zend_always_inline zval *_zend_hash_append(HashTable *ht, zend_string *key, zval *zv)
931 {
932 uint32_t idx = ht->nNumUsed++;
933 uint32_t nIndex;
934 Bucket *p = ht->arData + idx;
935
936 ZVAL_COPY_VALUE(&p->val, zv);
937 if (!ZSTR_IS_INTERNED(key)) {
938 ht->u.flags &= ~HASH_FLAG_STATIC_KEYS;
939 zend_string_addref(key);
940 zend_string_hash_val(key);
941 }
942 p->key = key;
943 p->h = ZSTR_H(key);
944 nIndex = (uint32_t)p->h | ht->nTableMask;
945 Z_NEXT(p->val) = HT_HASH(ht, nIndex);
946 HT_HASH(ht, nIndex) = HT_IDX_TO_HASH(idx);
947 ht->nNumUsed = idx + 1;
948 ht->nNumOfElements++;
949 return &p->val;
950 }
951
_zend_hash_append_ptr(HashTable * ht,zend_string * key,void * ptr)952 static zend_always_inline zval *_zend_hash_append_ptr(HashTable *ht, zend_string *key, void *ptr)
953 {
954 uint32_t idx = ht->nNumUsed++;
955 uint32_t nIndex;
956 Bucket *p = ht->arData + idx;
957
958 ZVAL_PTR(&p->val, ptr);
959 if (!ZSTR_IS_INTERNED(key)) {
960 ht->u.flags &= ~HASH_FLAG_STATIC_KEYS;
961 zend_string_addref(key);
962 zend_string_hash_val(key);
963 }
964 p->key = key;
965 p->h = ZSTR_H(key);
966 nIndex = (uint32_t)p->h | ht->nTableMask;
967 Z_NEXT(p->val) = HT_HASH(ht, nIndex);
968 HT_HASH(ht, nIndex) = HT_IDX_TO_HASH(idx);
969 ht->nNumUsed = idx + 1;
970 ht->nNumOfElements++;
971 return &p->val;
972 }
973
_zend_hash_append_ind(HashTable * ht,zend_string * key,zval * ptr)974 static zend_always_inline void _zend_hash_append_ind(HashTable *ht, zend_string *key, zval *ptr)
975 {
976 uint32_t idx = ht->nNumUsed++;
977 uint32_t nIndex;
978 Bucket *p = ht->arData + idx;
979
980 ZVAL_INDIRECT(&p->val, ptr);
981 if (!ZSTR_IS_INTERNED(key)) {
982 ht->u.flags &= ~HASH_FLAG_STATIC_KEYS;
983 zend_string_addref(key);
984 zend_string_hash_val(key);
985 }
986 p->key = key;
987 p->h = ZSTR_H(key);
988 nIndex = (uint32_t)p->h | ht->nTableMask;
989 Z_NEXT(p->val) = HT_HASH(ht, nIndex);
990 HT_HASH(ht, nIndex) = HT_IDX_TO_HASH(idx);
991 ht->nNumUsed = idx + 1;
992 ht->nNumOfElements++;
993 }
994
995 #endif /* ZEND_HASH_H */
996
997 /*
998 * Local variables:
999 * tab-width: 4
1000 * c-basic-offset: 4
1001 * indent-tabs-mode: t
1002 * End:
1003 */
1004