Skip to content

Commit 980bb54

Browse files
committed
Convert macros to inline functions in zend_hash
1 parent 61989cc commit 980bb54

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

Zend/zend_hash.c

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

23752375

23762376
/* This function should be made binary safe */
2377-
ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_ex(const HashTable *ht, zend_string **str_index, zend_ulong *num_index, HashPosition *pos)
2377+
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)
23782378
{
23792379
uint32_t idx;
23802380
Bucket *p;
@@ -2394,7 +2394,7 @@ ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_ex(const HashTable *ht, zen
23942394
return HASH_KEY_NON_EXISTENT;
23952395
}
23962396

2397-
ZEND_API void ZEND_FASTCALL zend_hash_get_current_key_zval_ex(const HashTable *ht, zval *key, HashPosition *pos)
2397+
ZEND_API void ZEND_FASTCALL zend_hash_get_current_key_zval_ex(const HashTable *ht, zval *key, const HashPosition *pos)
23982398
{
23992399
uint32_t idx;
24002400
Bucket *p;

Zend/zend_hash.h

Lines changed: 38 additions & 24 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
@@ -225,35 +226,45 @@ static zend_always_inline zend_bool zend_hash_index_exists(const HashTable *ht,
225226
/* traversing */
226227
ZEND_API HashPosition ZEND_FASTCALL zend_hash_get_current_pos(const HashTable *ht);
227228

228-
#define zend_hash_has_more_elements_ex(ht, pos) \
229-
(zend_hash_get_current_key_type_ex(ht, pos) == HASH_KEY_NON_EXISTENT ? FAILURE : SUCCESS)
230229
ZEND_API zend_result ZEND_FASTCALL zend_hash_move_forward_ex(HashTable *ht, HashPosition *pos);
231230
ZEND_API zend_result ZEND_FASTCALL zend_hash_move_backwards_ex(HashTable *ht, HashPosition *pos);
232-
ZEND_API zend_result ZEND_FASTCALL zend_hash_get_current_key_ex(const HashTable *ht, zend_string **str_index, zend_ulong *num_index, HashPosition *pos);
233-
ZEND_API void ZEND_FASTCALL zend_hash_get_current_key_zval_ex(const HashTable *ht, zval *key, HashPosition *pos);
231+
ZEND_API zend_result ZEND_FASTCALL zend_hash_get_current_key_ex(const HashTable *ht, zend_string **str_index, zend_ulong *num_index, const HashPosition *pos);
232+
ZEND_API void ZEND_FASTCALL zend_hash_get_current_key_zval_ex(const HashTable *ht, zval *key, const HashPosition *pos);
234233
ZEND_API zend_result ZEND_FASTCALL zend_hash_get_current_key_type_ex(HashTable *ht, HashPosition *pos);
235234
ZEND_API zval* ZEND_FASTCALL zend_hash_get_current_data_ex(HashTable *ht, HashPosition *pos);
236235
ZEND_API void ZEND_FASTCALL zend_hash_internal_pointer_reset_ex(HashTable *ht, HashPosition *pos);
237236
ZEND_API void ZEND_FASTCALL zend_hash_internal_pointer_end_ex(HashTable *ht, HashPosition *pos);
238237

239-
#define zend_hash_has_more_elements(ht) \
240-
zend_hash_has_more_elements_ex(ht, &(ht)->nInternalPointer)
241-
#define zend_hash_move_forward(ht) \
242-
zend_hash_move_forward_ex(ht, &(ht)->nInternalPointer)
243-
#define zend_hash_move_backwards(ht) \
244-
zend_hash_move_backwards_ex(ht, &(ht)->nInternalPointer)
245-
#define zend_hash_get_current_key(ht, str_index, num_index) \
246-
zend_hash_get_current_key_ex(ht, str_index, num_index, &(ht)->nInternalPointer)
247-
#define zend_hash_get_current_key_zval(ht, key) \
248-
zend_hash_get_current_key_zval_ex(ht, key, &(ht)->nInternalPointer)
249-
#define zend_hash_get_current_key_type(ht) \
250-
zend_hash_get_current_key_type_ex(ht, &(ht)->nInternalPointer)
251-
#define zend_hash_get_current_data(ht) \
252-
zend_hash_get_current_data_ex(ht, &(ht)->nInternalPointer)
253-
#define zend_hash_internal_pointer_reset(ht) \
254-
zend_hash_internal_pointer_reset_ex(ht, &(ht)->nInternalPointer)
255-
#define zend_hash_internal_pointer_end(ht) \
256-
zend_hash_internal_pointer_end_ex(ht, &(ht)->nInternalPointer)
238+
static zend_always_inline zend_result zend_hash_has_more_elements_ex(HashTable *ht, HashPosition *pos) {
239+
return (zend_hash_get_current_key_type_ex(ht, pos) == HASH_KEY_NON_EXISTENT ? FAILURE : SUCCESS);
240+
}
241+
static inline zend_result zend_hash_has_more_elements(HashTable *ht) {
242+
return zend_hash_has_more_elements_ex(ht, &ht->nInternalPointer);
243+
}
244+
static inline zend_result zend_hash_move_forward(HashTable *ht) {
245+
return zend_hash_move_forward_ex(ht, &ht->nInternalPointer);
246+
}
247+
static inline zend_result zend_hash_move_backwards(HashTable *ht) {
248+
return zend_hash_move_backwards_ex(ht, &ht->nInternalPointer);
249+
}
250+
static inline zend_result zend_hash_get_current_key(const HashTable *ht, zend_string **str_index, zend_ulong *num_index) {
251+
return zend_hash_get_current_key_ex(ht, str_index, num_index, &ht->nInternalPointer);
252+
}
253+
static inline void zend_hash_get_current_key_zval(const HashTable *ht, zval *key) {
254+
zend_hash_get_current_key_zval_ex(ht, key, &ht->nInternalPointer);
255+
}
256+
static inline zend_result zend_hash_get_current_key_type(HashTable *ht) {
257+
return zend_hash_get_current_key_type_ex(ht, &ht->nInternalPointer);
258+
}
259+
static inline zval* zend_hash_get_current_data(HashTable *ht) {
260+
return zend_hash_get_current_data_ex(ht, &ht->nInternalPointer);
261+
}
262+
static inline void zend_hash_internal_pointer_reset(HashTable *ht) {
263+
zend_hash_internal_pointer_reset_ex(ht, &ht->nInternalPointer);
264+
}
265+
static inline void zend_hash_internal_pointer_end(HashTable *ht) {
266+
zend_hash_internal_pointer_end_ex(ht, &ht->nInternalPointer);
267+
}
257268

258269
/* Copying, merging and sorting */
259270
ZEND_API void ZEND_FASTCALL zend_hash_copy(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor);
@@ -268,9 +279,11 @@ ZEND_API int zend_hash_compare(HashTable *ht1, HashTable *ht2, compare_func_t
268279
ZEND_API void ZEND_FASTCALL zend_hash_sort_ex(HashTable *ht, sort_func_t sort_func, bucket_compare_func_t compare_func, zend_bool renumber);
269280
ZEND_API zval* ZEND_FASTCALL zend_hash_minmax(const HashTable *ht, bucket_compare_func_t compar, uint32_t flag);
270281

271-
#define zend_hash_sort(ht, compare_func, renumber) \
272-
zend_hash_sort_ex(ht, zend_sort, compare_func, renumber)
282+
static inline void ZEND_FASTCALL zend_hash_sort(HashTable *ht, bucket_compare_func_t compare_func, zend_bool renumber) {
283+
zend_hash_sort_ex(ht, zend_sort, compare_func, renumber);
284+
}
273285

286+
// TODO Inline functions?
274287
#define zend_hash_num_elements(ht) \
275288
(ht)->nNumOfElements
276289

@@ -345,6 +358,7 @@ static zend_always_inline void zend_hash_release(zend_array *array)
345358

346359
END_EXTERN_C()
347360

361+
// TODO Inline functions?
348362
#define ZEND_INIT_SYMTABLE(ht) \
349363
ZEND_INIT_SYMTABLE_EX(ht, 8, 0)
350364

0 commit comments

Comments
 (0)