Skip to content

Commit

Permalink
Zend/zend_hash.(c|h): Mark various parameters and variables const (ph…
Browse files Browse the repository at this point in the history
  • Loading branch information
Girgias authored Sep 25, 2024
1 parent ae505db commit 2c3c238
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 55 deletions.
72 changes: 36 additions & 36 deletions Zend/zend_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ ZEND_API HashTable* ZEND_FASTCALL _zend_new_array(uint32_t nSize)
return ht;
}

ZEND_API HashTable* ZEND_FASTCALL zend_new_pair(zval *val1, zval *val2)
ZEND_API HashTable* ZEND_FASTCALL zend_new_pair(const zval *val1, const zval *val2)
{
zval *zv;
HashTable *ht = emalloc(sizeof(HashTable));
Expand Down Expand Up @@ -457,7 +457,7 @@ ZEND_API void ZEND_FASTCALL zend_hash_discard(HashTable *ht, uint32_t nNumUsed)
}
}

static uint32_t zend_array_recalc_elements(HashTable *ht)
static uint32_t zend_array_recalc_elements(const HashTable *ht)
{
zval *val;
uint32_t num = ht->nNumOfElements;
Expand Down Expand Up @@ -671,10 +671,10 @@ ZEND_API void ZEND_FASTCALL zend_hash_iterator_del(uint32_t idx)
}
}

static zend_never_inline void ZEND_FASTCALL _zend_hash_iterators_remove(HashTable *ht)
static zend_never_inline void ZEND_FASTCALL _zend_hash_iterators_remove(const HashTable *ht)
{
HashTableIterator *iter = EG(ht_iterators);
HashTableIterator *end = iter + EG(ht_iterators_used);
const HashTableIterator *end = iter + EG(ht_iterators_used);

while (iter != end) {
if (iter->ht == ht) {
Expand All @@ -684,17 +684,17 @@ static zend_never_inline void ZEND_FASTCALL _zend_hash_iterators_remove(HashTabl
}
}

static zend_always_inline void zend_hash_iterators_remove(HashTable *ht)
static zend_always_inline void zend_hash_iterators_remove(const HashTable *ht)
{
if (UNEXPECTED(HT_HAS_ITERATORS(ht))) {
_zend_hash_iterators_remove(ht);
}
}

ZEND_API HashPosition ZEND_FASTCALL zend_hash_iterators_lower_pos(HashTable *ht, HashPosition start)
ZEND_API HashPosition ZEND_FASTCALL zend_hash_iterators_lower_pos(const HashTable *ht, HashPosition start)
{
HashTableIterator *iter = EG(ht_iterators);
HashTableIterator *end = iter + EG(ht_iterators_used);
const HashTableIterator *iter = EG(ht_iterators);
const HashTableIterator *end = iter + EG(ht_iterators_used);
HashPosition res = ht->nNumUsed;

while (iter != end) {
Expand All @@ -708,10 +708,10 @@ ZEND_API HashPosition ZEND_FASTCALL zend_hash_iterators_lower_pos(HashTable *ht,
return res;
}

ZEND_API void ZEND_FASTCALL _zend_hash_iterators_update(HashTable *ht, HashPosition from, HashPosition to)
ZEND_API void ZEND_FASTCALL _zend_hash_iterators_update(const HashTable *ht, HashPosition from, HashPosition to)
{
HashTableIterator *iter = EG(ht_iterators);
HashTableIterator *end = iter + EG(ht_iterators_used);
const HashTableIterator *end = iter + EG(ht_iterators_used);

while (iter != end) {
if (iter->ht == ht && iter->pos == from) {
Expand All @@ -721,10 +721,10 @@ ZEND_API void ZEND_FASTCALL _zend_hash_iterators_update(HashTable *ht, HashPosit
}
}

ZEND_API void ZEND_FASTCALL zend_hash_iterators_advance(HashTable *ht, HashPosition step)
ZEND_API void ZEND_FASTCALL zend_hash_iterators_advance(const HashTable *ht, HashPosition step)
{
HashTableIterator *iter = EG(ht_iterators);
HashTableIterator *end = iter + EG(ht_iterators_used);
const HashTableIterator *end = iter + EG(ht_iterators_used);

while (iter != end) {
if (iter->ht == ht) {
Expand Down Expand Up @@ -1429,11 +1429,11 @@ ZEND_API void ZEND_FASTCALL zend_hash_rehash(HashTable *ht)
}
}

static zend_always_inline void zend_hash_iterators_clamp_max(HashTable *ht, uint32_t max)
static zend_always_inline void zend_hash_iterators_clamp_max(const HashTable *ht, uint32_t max)
{
if (UNEXPECTED(HT_HAS_ITERATORS(ht))) {
HashTableIterator *iter = EG(ht_iterators);
HashTableIterator *end = iter + EG(ht_iterators_used);
const HashTableIterator *end = iter + EG(ht_iterators_used);
while (iter != end) {
if (iter->ht == ht) {
iter->pos = MIN(iter->pos, max);
Expand Down Expand Up @@ -2237,7 +2237,7 @@ ZEND_API void ZEND_FASTCALL zend_hash_reverse_apply(HashTable *ht, apply_func_t
}


ZEND_API void ZEND_FASTCALL zend_hash_copy(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor)
ZEND_API void ZEND_FASTCALL zend_hash_copy(HashTable *target, const HashTable *source, copy_ctor_func_t pCopyConstructor)
{
uint32_t idx;
zval *new_entry, *data;
Expand Down Expand Up @@ -2284,7 +2284,7 @@ ZEND_API void ZEND_FASTCALL zend_hash_copy(HashTable *target, HashTable *source,
}


static zend_always_inline bool zend_array_dup_value(HashTable *source, HashTable *target, zval *data, zval *dest, bool packed, bool with_holes)
static zend_always_inline bool zend_array_dup_value(const HashTable *source, zval *data, zval *dest, bool packed, bool with_holes)
{
if (with_holes) {
if (!packed && Z_TYPE_INFO_P(data) == IS_INDIRECT) {
Expand Down Expand Up @@ -2321,9 +2321,9 @@ static zend_always_inline bool zend_array_dup_value(HashTable *source, HashTable
return 1;
}

static zend_always_inline bool zend_array_dup_element(HashTable *source, HashTable *target, uint32_t idx, Bucket *p, Bucket *q, bool packed, bool static_keys, bool with_holes)
static zend_always_inline bool zend_array_dup_element(const HashTable *source, HashTable *target, uint32_t idx, Bucket *p, Bucket *q, bool packed, bool static_keys, bool with_holes)
{
if (!zend_array_dup_value(source, target, &p->val, &q->val, packed, with_holes)) {
if (!zend_array_dup_value(source, &p->val, &q->val, packed, with_holes)) {
return 0;
}

Expand All @@ -2344,9 +2344,9 @@ static zend_always_inline bool zend_array_dup_element(HashTable *source, HashTab
}

// We need to duplicate iterators to be able to search through all copy-on-write copies to find the actually iterated HashTable and position back
static void zend_array_dup_ht_iterators(HashTable *source, HashTable *target) {
static void zend_array_dup_ht_iterators(const HashTable *source, HashTable *target) {
HashTableIterator *iter = EG(ht_iterators);
HashTableIterator *end = iter + EG(ht_iterators_used);
const HashTableIterator *end = iter + EG(ht_iterators_used);

while (iter != end) {
if (iter->ht == source) {
Expand All @@ -2359,14 +2359,14 @@ static void zend_array_dup_ht_iterators(HashTable *source, HashTable *target) {
}
}

static zend_always_inline void zend_array_dup_packed_elements(HashTable *source, HashTable *target, bool with_holes)
static zend_always_inline void zend_array_dup_packed_elements(const HashTable *source, HashTable *target, bool with_holes)
{
zval *p = source->arPacked;
zval *q = target->arPacked;
zval *end = p + source->nNumUsed;
const zval *end = p + source->nNumUsed;

do {
if (!zend_array_dup_value(source, target, p, q, 1, with_holes)) {
if (!zend_array_dup_value(source, p, q, 1, with_holes)) {
if (with_holes) {
ZVAL_UNDEF(q);
}
Expand All @@ -2379,12 +2379,12 @@ static zend_always_inline void zend_array_dup_packed_elements(HashTable *source,
}
}

static zend_always_inline uint32_t zend_array_dup_elements(HashTable *source, HashTable *target, bool static_keys, bool with_holes)
static zend_always_inline uint32_t zend_array_dup_elements(const HashTable *source, HashTable *target, bool static_keys, bool with_holes)
{
uint32_t idx = 0;
Bucket *p = source->arData;
Bucket *q = target->arData;
Bucket *end = p + source->nNumUsed;
const Bucket *end = p + source->nNumUsed;

if (UNEXPECTED(HT_HAS_ITERATORS(source))) {
zend_array_dup_ht_iterators(source, target);
Expand Down Expand Up @@ -2432,7 +2432,7 @@ static zend_always_inline uint32_t zend_array_dup_elements(HashTable *source, Ha
return idx;
}

ZEND_API HashTable* ZEND_FASTCALL zend_array_dup(HashTable *source)
ZEND_API HashTable* ZEND_FASTCALL zend_array_dup(const HashTable *source)
{
uint32_t idx;
HashTable *target;
Expand Down Expand Up @@ -2520,7 +2520,7 @@ ZEND_API HashTable* ZEND_FASTCALL zend_array_dup(HashTable *source)
return target;
}

ZEND_API HashTable* zend_array_to_list(HashTable *source)
ZEND_API HashTable* zend_array_to_list(const HashTable *source)
{
HashTable *result = _zend_new_array(zend_hash_num_elements(source));
zend_hash_real_init_packed(result);
Expand All @@ -2541,7 +2541,7 @@ ZEND_API HashTable* zend_array_to_list(HashTable *source)
}


ZEND_API void ZEND_FASTCALL zend_hash_merge(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, bool overwrite)
ZEND_API void ZEND_FASTCALL zend_hash_merge(HashTable *target, const HashTable *source, copy_ctor_func_t pCopyConstructor, bool overwrite)
{
uint32_t idx;
Bucket *p;
Expand Down Expand Up @@ -2637,7 +2637,7 @@ static bool ZEND_FASTCALL zend_hash_replace_checker_wrapper(HashTable *target, z
}


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)
ZEND_API void ZEND_FASTCALL zend_hash_merge_ex(HashTable *target, const HashTable *source, copy_ctor_func_t pCopyConstructor, merge_checker_func_t pMergeSource, void *pParam)
{
uint32_t idx;
Bucket *p;
Expand Down Expand Up @@ -2727,7 +2727,7 @@ ZEND_API zval* ZEND_FASTCALL _zend_hash_index_find(const HashTable *ht, zend_ulo
return p ? &p->val : NULL;
}

ZEND_API void ZEND_FASTCALL zend_hash_internal_pointer_reset_ex(HashTable *ht, HashPosition *pos)
ZEND_API void ZEND_FASTCALL zend_hash_internal_pointer_reset_ex(const HashTable *ht, HashPosition *pos)
{
IS_CONSISTENT(ht);
HT_ASSERT(ht, &ht->nInternalPointer != pos || GC_REFCOUNT(ht) == 1);
Expand All @@ -2738,7 +2738,7 @@ ZEND_API void ZEND_FASTCALL zend_hash_internal_pointer_reset_ex(HashTable *ht, H
/* This function will be extremely optimized by remembering
* the end of the list
*/
ZEND_API void ZEND_FASTCALL zend_hash_internal_pointer_end_ex(HashTable *ht, HashPosition *pos)
ZEND_API void ZEND_FASTCALL zend_hash_internal_pointer_end_ex(const HashTable *ht, HashPosition *pos)
{
uint32_t idx;

Expand Down Expand Up @@ -2767,7 +2767,7 @@ ZEND_API void ZEND_FASTCALL zend_hash_internal_pointer_end_ex(HashTable *ht, Has
}


ZEND_API zend_result ZEND_FASTCALL zend_hash_move_forward_ex(HashTable *ht, HashPosition *pos)
ZEND_API zend_result ZEND_FASTCALL zend_hash_move_forward_ex(const HashTable *ht, HashPosition *pos)
{
uint32_t idx;

Expand Down Expand Up @@ -2806,7 +2806,7 @@ ZEND_API zend_result ZEND_FASTCALL zend_hash_move_forward_ex(HashTable *ht, Hash
}
}

ZEND_API zend_result ZEND_FASTCALL zend_hash_move_backwards_ex(HashTable *ht, HashPosition *pos)
ZEND_API zend_result ZEND_FASTCALL zend_hash_move_backwards_ex(const HashTable *ht, HashPosition *pos)
{
uint32_t idx = *pos;

Expand Down Expand Up @@ -2887,7 +2887,7 @@ ZEND_API void ZEND_FASTCALL zend_hash_get_current_key_zval_ex(const HashTable *h
}
}

ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_type_ex(HashTable *ht, HashPosition *pos)
ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_type_ex(const HashTable *ht, const HashPosition *pos)
{
uint32_t idx;
Bucket *p;
Expand All @@ -2909,7 +2909,7 @@ ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_type_ex(HashTable *ht, Hash
}


ZEND_API zval* ZEND_FASTCALL zend_hash_get_current_data_ex(HashTable *ht, HashPosition *pos)
ZEND_API zval* ZEND_FASTCALL zend_hash_get_current_data_ex(const HashTable *ht, const HashPosition *pos)
{
uint32_t idx;
Bucket *p;
Expand Down Expand Up @@ -3063,7 +3063,7 @@ ZEND_API void ZEND_FASTCALL zend_hash_sort_ex(HashTable *ht, sort_func_t sort, b
}
}

static zend_always_inline int zend_hash_compare_impl(HashTable *ht1, HashTable *ht2, compare_func_t compar, bool ordered) {
static zend_always_inline int zend_hash_compare_impl(const HashTable *ht1, const HashTable *ht2, compare_func_t compar, bool ordered) {
uint32_t idx1, idx2;
zend_string *key1, *key2;
zend_ulong h1, h2;
Expand Down
38 changes: 19 additions & 19 deletions Zend/zend_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,16 @@ static zend_always_inline bool zend_hash_index_exists(const HashTable *ht, zend_
ZEND_API HashPosition ZEND_FASTCALL zend_hash_get_current_pos_ex(const HashTable *ht, HashPosition pos);
ZEND_API HashPosition ZEND_FASTCALL zend_hash_get_current_pos(const HashTable *ht);

ZEND_API zend_result ZEND_FASTCALL zend_hash_move_forward_ex(HashTable *ht, HashPosition *pos);
ZEND_API zend_result ZEND_FASTCALL zend_hash_move_backwards_ex(HashTable *ht, HashPosition *pos);
ZEND_API zend_result ZEND_FASTCALL zend_hash_move_forward_ex(const HashTable *ht, HashPosition *pos);
ZEND_API zend_result ZEND_FASTCALL zend_hash_move_backwards_ex(const HashTable *ht, HashPosition *pos);
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);
ZEND_API void ZEND_FASTCALL zend_hash_get_current_key_zval_ex(const HashTable *ht, zval *key, const HashPosition *pos);
ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_type_ex(HashTable *ht, HashPosition *pos);
ZEND_API zval* ZEND_FASTCALL zend_hash_get_current_data_ex(HashTable *ht, HashPosition *pos);
ZEND_API void ZEND_FASTCALL zend_hash_internal_pointer_reset_ex(HashTable *ht, HashPosition *pos);
ZEND_API void ZEND_FASTCALL zend_hash_internal_pointer_end_ex(HashTable *ht, HashPosition *pos);
ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_type_ex(const HashTable *ht, const HashPosition *pos);
ZEND_API zval* ZEND_FASTCALL zend_hash_get_current_data_ex(const HashTable *ht, const HashPosition *pos);
ZEND_API void ZEND_FASTCALL zend_hash_internal_pointer_reset_ex(const HashTable *ht, HashPosition *pos);
ZEND_API void ZEND_FASTCALL zend_hash_internal_pointer_end_ex(const HashTable *ht, HashPosition *pos);

static zend_always_inline zend_result zend_hash_has_more_elements_ex(HashTable *ht, HashPosition *pos) {
static zend_always_inline zend_result zend_hash_has_more_elements_ex(const HashTable *ht, const HashPosition *pos) {
return (zend_hash_get_current_key_type_ex(ht, pos) == HASH_KEY_NON_EXISTENT ? FAILURE : SUCCESS);
}
static zend_always_inline zend_result zend_hash_has_more_elements(HashTable *ht) {
Expand All @@ -275,10 +275,10 @@ static zend_always_inline int zend_hash_get_current_key(const HashTable *ht, zen
static zend_always_inline void zend_hash_get_current_key_zval(const HashTable *ht, zval *key) {
zend_hash_get_current_key_zval_ex(ht, key, &ht->nInternalPointer);
}
static zend_always_inline int zend_hash_get_current_key_type(HashTable *ht) {
static zend_always_inline int zend_hash_get_current_key_type(const HashTable *ht) {
return zend_hash_get_current_key_type_ex(ht, &ht->nInternalPointer);
}
static zend_always_inline zval* zend_hash_get_current_data(HashTable *ht) {
static zend_always_inline zval* zend_hash_get_current_data(const HashTable *ht) {
return zend_hash_get_current_data_ex(ht, &ht->nInternalPointer);
}
static zend_always_inline void zend_hash_internal_pointer_reset(HashTable *ht) {
Expand All @@ -289,9 +289,9 @@ static zend_always_inline void zend_hash_internal_pointer_end(HashTable *ht) {
}

/* Copying, merging and sorting */
ZEND_API void ZEND_FASTCALL zend_hash_copy(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor);
ZEND_API void ZEND_FASTCALL zend_hash_merge(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, bool overwrite);
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);
ZEND_API void ZEND_FASTCALL zend_hash_copy(HashTable *target, const HashTable *source, copy_ctor_func_t pCopyConstructor);
ZEND_API void ZEND_FASTCALL zend_hash_merge(HashTable *target, const HashTable *source, copy_ctor_func_t pCopyConstructor, bool overwrite);
ZEND_API void ZEND_FASTCALL zend_hash_merge_ex(HashTable *target, const HashTable *source, copy_ctor_func_t pCopyConstructor, merge_checker_func_t pMergeSource, void *pParam);
ZEND_API void zend_hash_bucket_swap(Bucket *p, Bucket *q);
ZEND_API void zend_hash_bucket_renum_swap(Bucket *p, Bucket *q);
ZEND_API void zend_hash_bucket_packed_swap(Bucket *p, Bucket *q);
Expand Down Expand Up @@ -333,11 +333,11 @@ ZEND_API void ZEND_FASTCALL zend_hash_rehash(HashTable *ht);

ZEND_API HashTable* ZEND_FASTCALL _zend_new_array_0(void);
ZEND_API HashTable* ZEND_FASTCALL _zend_new_array(uint32_t size);
ZEND_API HashTable* ZEND_FASTCALL zend_new_pair(zval *val1, zval *val2);
ZEND_API HashTable* ZEND_FASTCALL zend_new_pair(const zval *val1, const zval *val2);
ZEND_API uint32_t zend_array_count(HashTable *ht);
ZEND_API HashTable* ZEND_FASTCALL zend_array_dup(HashTable *source);
ZEND_API HashTable* ZEND_FASTCALL zend_array_dup(const HashTable *source);
ZEND_API void ZEND_FASTCALL zend_array_destroy(HashTable *ht);
ZEND_API HashTable* zend_array_to_list(HashTable *source);
ZEND_API HashTable* zend_array_to_list(const HashTable *source);
ZEND_API void ZEND_FASTCALL zend_symtable_clean(HashTable *ht);
ZEND_API HashTable* ZEND_FASTCALL zend_symtable_to_proptable(HashTable *ht);
ZEND_API HashTable* ZEND_FASTCALL zend_proptable_to_symtable(HashTable *ht, bool always_duplicate);
Expand All @@ -348,11 +348,11 @@ ZEND_API uint32_t ZEND_FASTCALL zend_hash_iterator_add(HashTable *ht, HashPo
ZEND_API HashPosition ZEND_FASTCALL zend_hash_iterator_pos(uint32_t idx, HashTable *ht);
ZEND_API HashPosition ZEND_FASTCALL zend_hash_iterator_pos_ex(uint32_t idx, zval *array);
ZEND_API void ZEND_FASTCALL zend_hash_iterator_del(uint32_t idx);
ZEND_API HashPosition ZEND_FASTCALL zend_hash_iterators_lower_pos(HashTable *ht, HashPosition start);
ZEND_API void ZEND_FASTCALL _zend_hash_iterators_update(HashTable *ht, HashPosition from, HashPosition to);
ZEND_API void ZEND_FASTCALL zend_hash_iterators_advance(HashTable *ht, HashPosition step);
ZEND_API HashPosition ZEND_FASTCALL zend_hash_iterators_lower_pos(const HashTable *ht, HashPosition start);
ZEND_API void ZEND_FASTCALL _zend_hash_iterators_update(const HashTable *ht, HashPosition from, HashPosition to);
ZEND_API void ZEND_FASTCALL zend_hash_iterators_advance(const HashTable *ht, HashPosition step);

static zend_always_inline void zend_hash_iterators_update(HashTable *ht, HashPosition from, HashPosition to)
static zend_always_inline void zend_hash_iterators_update(const HashTable *ht, HashPosition from, HashPosition to)
{
if (UNEXPECTED(HT_HAS_ITERATORS(ht))) {
_zend_hash_iterators_update(ht, from, to);
Expand Down

0 comments on commit 2c3c238

Please sign in to comment.