@@ -2928,28 +2928,28 @@ static HashTable *interned_type_tree = NULL;
2928
2928
list[count++] = value; \
2929
2929
} while (0)
2930
2930
2931
- static int compare_simple_types (zend_type a , zend_type b ) {
2932
- uint32_t a_mask = ZEND_TYPE_FULL_MASK (a );
2933
- uint32_t b_mask = ZEND_TYPE_FULL_MASK (b );
2931
+ static int compare_simple_types (const zend_type a , const zend_type b ) {
2932
+ const uint32_t a_mask = ZEND_TYPE_FULL_MASK (a );
2933
+ const uint32_t b_mask = ZEND_TYPE_FULL_MASK (b );
2934
2934
2935
2935
if (a_mask != b_mask ) {
2936
2936
return a_mask < b_mask ? -1 : 1 ;
2937
2937
}
2938
2938
2939
- bool a_has_name = ZEND_TYPE_HAS_NAME (a );
2940
- bool b_has_name = ZEND_TYPE_HAS_NAME (b );
2939
+ const bool a_has_name = ZEND_TYPE_HAS_NAME (a );
2940
+ const bool b_has_name = ZEND_TYPE_HAS_NAME (b );
2941
2941
2942
2942
if (a_has_name && b_has_name ) {
2943
- zend_string * a_name = ZEND_TYPE_NAME (a );
2944
- zend_string * b_name = ZEND_TYPE_NAME (b );
2945
- int cmp = ZSTR_VAL (a_name ) == ZSTR_VAL (b_name );
2943
+ const zend_string * a_name = ZEND_TYPE_NAME (a );
2944
+ const zend_string * b_name = ZEND_TYPE_NAME (b );
2945
+ const int cmp = ZSTR_VAL (a_name ) == ZSTR_VAL (b_name );
2946
2946
if (cmp != 0 ) {
2947
2947
return cmp ;
2948
2948
}
2949
2949
}
2950
2950
2951
- bool a_nullable = ZEND_TYPE_ALLOW_NULL (a );
2952
- bool b_nullable = ZEND_TYPE_ALLOW_NULL (b );
2951
+ const bool a_nullable = ZEND_TYPE_ALLOW_NULL (a );
2952
+ const bool b_nullable = ZEND_TYPE_ALLOW_NULL (b );
2953
2953
2954
2954
if (a_nullable != b_nullable ) {
2955
2955
return a_nullable ? 1 : -1 ;
@@ -2960,11 +2960,11 @@ static int compare_simple_types(zend_type a, zend_type b) {
2960
2960
}
2961
2961
2962
2962
static int compare_type_nodes (const void * a_ , const void * b_ ) {
2963
- zend_type_node * a = * (zend_type_node * * )a_ ;
2964
- zend_type_node * b = * (zend_type_node * * )b_ ;
2963
+ const zend_type_node * a = * (zend_type_node * * )a_ ;
2964
+ const zend_type_node * b = * (zend_type_node * * )b_ ;
2965
2965
2966
2966
if (a -> kind != b -> kind ) {
2967
- return a -> kind - b -> kind ;
2967
+ return ( int ) a -> kind - ( int ) b -> kind ;
2968
2968
}
2969
2969
2970
2970
if (a -> kind == ZEND_TYPE_SIMPLE ) {
@@ -2985,15 +2985,15 @@ static int compare_type_nodes(const void *a_, const void *b_) {
2985
2985
return 0 ;
2986
2986
}
2987
2987
2988
- zend_ulong zend_type_node_hash (zend_type_node * node ) {
2988
+ zend_ulong zend_type_node_hash (const zend_type_node * node ) {
2989
2989
zend_ulong hash = 2166136261u ; // FNV-1a offset basis
2990
2990
2991
2991
hash ^= (zend_ulong )node -> kind ;
2992
2992
hash *= 16777619 ;
2993
2993
2994
2994
switch (node -> kind ) {
2995
2995
case ZEND_TYPE_SIMPLE : {
2996
- zend_type type = node -> simple_type ;
2996
+ const zend_type type = node -> simple_type ;
2997
2997
hash ^= (zend_ulong )ZEND_TYPE_FULL_MASK (type );
2998
2998
hash *= 16777619 ;
2999
2999
@@ -3009,7 +3009,7 @@ zend_ulong zend_type_node_hash(zend_type_node *node) {
3009
3009
case ZEND_TYPE_UNION :
3010
3010
case ZEND_TYPE_INTERSECTION : {
3011
3011
for (uint32_t i = 0 ; i < node -> compound .num_types ; ++ i ) {
3012
- zend_ulong child_hash = zend_type_node_hash (node -> compound .types [i ]);
3012
+ const zend_ulong child_hash = zend_type_node_hash (node -> compound .types [i ]);
3013
3013
hash ^= child_hash ;
3014
3014
hash *= 16777619 ;
3015
3015
}
@@ -3020,27 +3020,27 @@ zend_ulong zend_type_node_hash(zend_type_node *node) {
3020
3020
return hash ;
3021
3021
}
3022
3022
3023
- bool zend_type_node_equals (zend_type_node * a , zend_type_node * b ) {
3023
+ bool zend_type_node_equals (const zend_type_node * a , const zend_type_node * b ) {
3024
3024
if (a == b ) return true;
3025
3025
if (a -> kind != b -> kind ) return false;
3026
3026
3027
3027
if (a -> kind == ZEND_TYPE_SIMPLE ) {
3028
- zend_type at = a -> simple_type ;
3029
- zend_type bt = b -> simple_type ;
3028
+ const zend_type at = a -> simple_type ;
3029
+ const zend_type bt = b -> simple_type ;
3030
3030
3031
3031
if (ZEND_TYPE_FULL_MASK (at ) != ZEND_TYPE_FULL_MASK (bt )) {
3032
3032
return false;
3033
3033
}
3034
3034
3035
- bool a_has_name = ZEND_TYPE_HAS_NAME (at );
3036
- bool b_has_name = ZEND_TYPE_HAS_NAME (bt );
3035
+ const bool a_has_name = ZEND_TYPE_HAS_NAME (at );
3036
+ const bool b_has_name = ZEND_TYPE_HAS_NAME (bt );
3037
3037
if (a_has_name != b_has_name ) {
3038
3038
return false;
3039
3039
}
3040
3040
3041
3041
if (a_has_name ) {
3042
- zend_string * a_name = ZEND_TYPE_NAME (at );
3043
- zend_string * b_name = ZEND_TYPE_NAME (bt );
3042
+ const zend_string * a_name = ZEND_TYPE_NAME (at );
3043
+ const zend_string * b_name = ZEND_TYPE_NAME (bt );
3044
3044
if (!zend_string_equals (a_name , b_name )) {
3045
3045
return false;
3046
3046
}
@@ -3063,9 +3063,8 @@ bool zend_type_node_equals(zend_type_node *a, zend_type_node *b) {
3063
3063
return true;
3064
3064
}
3065
3065
3066
-
3067
3066
static zend_type_node * intern_type_node (zend_type_node * node ) {
3068
- zend_ulong hash = zend_type_node_hash (node );
3067
+ const zend_ulong hash = zend_type_node_hash (node );
3069
3068
zend_type_node * existing ;
3070
3069
3071
3070
if (interned_type_tree == NULL ) {
@@ -3075,6 +3074,7 @@ static zend_type_node *intern_type_node(zend_type_node *node) {
3075
3074
3076
3075
if ((existing = zend_hash_index_find_ptr (interned_type_tree , hash ))) {
3077
3076
if (zend_type_node_equals (existing , node )) {
3077
+ pefree (node , 1 );
3078
3078
return existing ; // reuse interned node
3079
3079
}
3080
3080
}
@@ -3083,8 +3083,7 @@ static zend_type_node *intern_type_node(zend_type_node *node) {
3083
3083
return node ;
3084
3084
}
3085
3085
3086
-
3087
- ZEND_API zend_type_node * zend_type_to_interned_tree (zend_type type ) {
3086
+ ZEND_API zend_type_node * zend_type_to_interned_tree (const zend_type type ) {
3088
3087
if (type .type_mask == 0 ) {
3089
3088
return NULL ;
3090
3089
}
@@ -3097,7 +3096,7 @@ ZEND_API zend_type_node *zend_type_to_interned_tree(zend_type type) {
3097
3096
}
3098
3097
3099
3098
zend_type_list * list = ZEND_TYPE_LIST (type );
3100
- zend_type_node_kind kind = ZEND_TYPE_IS_INTERSECTION (type ) ?
3099
+ const zend_type_node_kind kind = ZEND_TYPE_IS_INTERSECTION (type ) ?
3101
3100
ZEND_TYPE_INTERSECTION : ZEND_TYPE_UNION ;
3102
3101
3103
3102
zend_type_node * * children = NULL ;
0 commit comments