Skip to content

Commit 64a46f1

Browse files
committed
Convert macros to inline functions in zend_hash
1 parent b4bec68 commit 64a46f1

File tree

2 files changed

+44
-30
lines changed

2 files changed

+44
-30
lines changed

Zend/zend_hash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,7 +2697,7 @@ ZEND_API zend_result ZEND_FASTCALL zend_hash_move_backwards_ex(HashTable *ht, Ha
26972697

26982698

26992699
/* This function should be made binary safe */
2700-
ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_ex(const HashTable *ht, zend_string **str_index, zend_ulong *num_index, HashPosition *pos)
2700+
ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_ex(const HashTable *ht, zend_string **str_index, zend_ulong *num_index, const HashPosition *pos)
27012701
{
27022702
uint32_t idx;
27032703
Bucket *p;
@@ -2721,7 +2721,7 @@ ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_ex(const HashTable *ht, zen
27212721
return HASH_KEY_NON_EXISTENT;
27222722
}
27232723

2724-
ZEND_API void ZEND_FASTCALL zend_hash_get_current_key_zval_ex(const HashTable *ht, zval *key, HashPosition *pos)
2724+
ZEND_API void ZEND_FASTCALL zend_hash_get_current_key_zval_ex(const HashTable *ht, zval *key, const HashPosition *pos)
27252725
{
27262726
uint32_t idx;
27272727
Bucket *p;

Zend/zend_hash.h

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define ZEND_HASH_H
2323

2424
#include "zend.h"
25+
#include "zend_sort.h"
2526

2627
#define HASH_KEY_IS_STRING 1
2728
#define HASH_KEY_IS_LONG 2
@@ -244,35 +245,45 @@ static zend_always_inline bool zend_hash_index_exists(const HashTable *ht, zend_
244245
/* traversing */
245246
ZEND_API HashPosition ZEND_FASTCALL zend_hash_get_current_pos(const HashTable *ht);
246247

247-
#define zend_hash_has_more_elements_ex(ht, pos) \
248-
(zend_hash_get_current_key_type_ex(ht, pos) == HASH_KEY_NON_EXISTENT ? FAILURE : SUCCESS)
249248
ZEND_API zend_result ZEND_FASTCALL zend_hash_move_forward_ex(HashTable *ht, HashPosition *pos);
250249
ZEND_API zend_result ZEND_FASTCALL zend_hash_move_backwards_ex(HashTable *ht, HashPosition *pos);
251-
ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_ex(const HashTable *ht, zend_string **str_index, zend_ulong *num_index, HashPosition *pos);
252-
ZEND_API void ZEND_FASTCALL zend_hash_get_current_key_zval_ex(const HashTable *ht, zval *key, HashPosition *pos);
250+
ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_ex(const HashTable *ht, zend_string **str_index, zend_ulong *num_index, const HashPosition *pos);
251+
ZEND_API void ZEND_FASTCALL zend_hash_get_current_key_zval_ex(const HashTable *ht, zval *key, const HashPosition *pos);
253252
ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_type_ex(HashTable *ht, HashPosition *pos);
254253
ZEND_API zval* ZEND_FASTCALL zend_hash_get_current_data_ex(HashTable *ht, HashPosition *pos);
255254
ZEND_API void ZEND_FASTCALL zend_hash_internal_pointer_reset_ex(HashTable *ht, HashPosition *pos);
256255
ZEND_API void ZEND_FASTCALL zend_hash_internal_pointer_end_ex(HashTable *ht, HashPosition *pos);
257256

258-
#define zend_hash_has_more_elements(ht) \
259-
zend_hash_has_more_elements_ex(ht, &(ht)->nInternalPointer)
260-
#define zend_hash_move_forward(ht) \
261-
zend_hash_move_forward_ex(ht, &(ht)->nInternalPointer)
262-
#define zend_hash_move_backwards(ht) \
263-
zend_hash_move_backwards_ex(ht, &(ht)->nInternalPointer)
264-
#define zend_hash_get_current_key(ht, str_index, num_index) \
265-
zend_hash_get_current_key_ex(ht, str_index, num_index, &(ht)->nInternalPointer)
266-
#define zend_hash_get_current_key_zval(ht, key) \
267-
zend_hash_get_current_key_zval_ex(ht, key, &(ht)->nInternalPointer)
268-
#define zend_hash_get_current_key_type(ht) \
269-
zend_hash_get_current_key_type_ex(ht, &(ht)->nInternalPointer)
270-
#define zend_hash_get_current_data(ht) \
271-
zend_hash_get_current_data_ex(ht, &(ht)->nInternalPointer)
272-
#define zend_hash_internal_pointer_reset(ht) \
273-
zend_hash_internal_pointer_reset_ex(ht, &(ht)->nInternalPointer)
274-
#define zend_hash_internal_pointer_end(ht) \
275-
zend_hash_internal_pointer_end_ex(ht, &(ht)->nInternalPointer)
257+
static zend_always_inline zend_result zend_hash_has_more_elements_ex(HashTable *ht, HashPosition *pos) {
258+
return (zend_hash_get_current_key_type_ex(ht, pos) == HASH_KEY_NON_EXISTENT ? FAILURE : SUCCESS);
259+
}
260+
static inline zend_result zend_hash_has_more_elements(HashTable *ht) {
261+
return zend_hash_has_more_elements_ex(ht, &ht->nInternalPointer);
262+
}
263+
static inline zend_result zend_hash_move_forward(HashTable *ht) {
264+
return zend_hash_move_forward_ex(ht, &ht->nInternalPointer);
265+
}
266+
static inline zend_result zend_hash_move_backwards(HashTable *ht) {
267+
return zend_hash_move_backwards_ex(ht, &ht->nInternalPointer);
268+
}
269+
static inline int zend_hash_get_current_key(const HashTable *ht, zend_string **str_index, zend_ulong *num_index) {
270+
return zend_hash_get_current_key_ex(ht, str_index, num_index, &ht->nInternalPointer);
271+
}
272+
static inline void zend_hash_get_current_key_zval(const HashTable *ht, zval *key) {
273+
zend_hash_get_current_key_zval_ex(ht, key, &ht->nInternalPointer);
274+
}
275+
static inline int zend_hash_get_current_key_type(HashTable *ht) {
276+
return zend_hash_get_current_key_type_ex(ht, &ht->nInternalPointer);
277+
}
278+
static inline zval* zend_hash_get_current_data(HashTable *ht) {
279+
return zend_hash_get_current_data_ex(ht, &ht->nInternalPointer);
280+
}
281+
static inline void zend_hash_internal_pointer_reset(HashTable *ht) {
282+
zend_hash_internal_pointer_reset_ex(ht, &ht->nInternalPointer);
283+
}
284+
static inline void zend_hash_internal_pointer_end(HashTable *ht) {
285+
zend_hash_internal_pointer_end_ex(ht, &ht->nInternalPointer);
286+
}
276287

277288
/* Copying, merging and sorting */
278289
ZEND_API void ZEND_FASTCALL zend_hash_copy(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor);
@@ -287,14 +298,17 @@ ZEND_API int zend_hash_compare(HashTable *ht1, HashTable *ht2, compare_func_t
287298
ZEND_API void ZEND_FASTCALL zend_hash_sort_ex(HashTable *ht, sort_func_t sort_func, bucket_compare_func_t compare_func, bool renumber);
288299
ZEND_API zval* ZEND_FASTCALL zend_hash_minmax(const HashTable *ht, compare_func_t compar, uint32_t flag);
289300

290-
#define zend_hash_sort(ht, compare_func, renumber) \
291-
zend_hash_sort_ex(ht, zend_sort, compare_func, renumber)
301+
static inline void ZEND_FASTCALL zend_hash_sort(HashTable *ht, bucket_compare_func_t compare_func, zend_bool renumber) {
302+
zend_hash_sort_ex(ht, zend_sort, compare_func, renumber);
303+
}
292304

293-
#define zend_hash_num_elements(ht) \
294-
(ht)->nNumOfElements
305+
static inline uint32_t zend_hash_num_elements(const HashTable *ht) {
306+
return ht->nNumOfElements;
307+
}
295308

296-
#define zend_hash_next_free_element(ht) \
297-
(ht)->nNextFreeElement
309+
static inline zend_long zend_hash_next_free_element(const HashTable *ht) {
310+
return ht->nNextFreeElement;
311+
}
298312

299313
ZEND_API void ZEND_FASTCALL zend_hash_rehash(HashTable *ht);
300314

0 commit comments

Comments
 (0)