@@ -2907,28 +2907,28 @@ static HashTable *interned_type_tree = NULL;
2907
2907
list[count++] = value; \
2908
2908
} while (0)
2909
2909
2910
- static int compare_simple_types (zend_type a , zend_type b ) {
2911
- uint32_t a_mask = ZEND_TYPE_FULL_MASK (a );
2912
- uint32_t b_mask = ZEND_TYPE_FULL_MASK (b );
2910
+ static int compare_simple_types (const zend_type a , const zend_type b ) {
2911
+ const uint32_t a_mask = ZEND_TYPE_FULL_MASK (a );
2912
+ const uint32_t b_mask = ZEND_TYPE_FULL_MASK (b );
2913
2913
2914
2914
if (a_mask != b_mask ) {
2915
2915
return a_mask < b_mask ? -1 : 1 ;
2916
2916
}
2917
2917
2918
- bool a_has_name = ZEND_TYPE_HAS_NAME (a );
2919
- bool b_has_name = ZEND_TYPE_HAS_NAME (b );
2918
+ const bool a_has_name = ZEND_TYPE_HAS_NAME (a );
2919
+ const bool b_has_name = ZEND_TYPE_HAS_NAME (b );
2920
2920
2921
2921
if (a_has_name && b_has_name ) {
2922
- zend_string * a_name = ZEND_TYPE_NAME (a );
2923
- zend_string * b_name = ZEND_TYPE_NAME (b );
2924
- int cmp = ZSTR_VAL (a_name ) == ZSTR_VAL (b_name );
2922
+ const zend_string * a_name = ZEND_TYPE_NAME (a );
2923
+ const zend_string * b_name = ZEND_TYPE_NAME (b );
2924
+ const int cmp = ZSTR_VAL (a_name ) == ZSTR_VAL (b_name );
2925
2925
if (cmp != 0 ) {
2926
2926
return cmp ;
2927
2927
}
2928
2928
}
2929
2929
2930
- bool a_nullable = ZEND_TYPE_ALLOW_NULL (a );
2931
- bool b_nullable = ZEND_TYPE_ALLOW_NULL (b );
2930
+ const bool a_nullable = ZEND_TYPE_ALLOW_NULL (a );
2931
+ const bool b_nullable = ZEND_TYPE_ALLOW_NULL (b );
2932
2932
2933
2933
if (a_nullable != b_nullable ) {
2934
2934
return a_nullable ? 1 : -1 ;
@@ -2939,11 +2939,11 @@ static int compare_simple_types(zend_type a, zend_type b) {
2939
2939
}
2940
2940
2941
2941
static int compare_type_nodes (const void * a_ , const void * b_ ) {
2942
- zend_type_node * a = * (zend_type_node * * )a_ ;
2943
- zend_type_node * b = * (zend_type_node * * )b_ ;
2942
+ const zend_type_node * a = * (zend_type_node * * )a_ ;
2943
+ const zend_type_node * b = * (zend_type_node * * )b_ ;
2944
2944
2945
2945
if (a -> kind != b -> kind ) {
2946
- return a -> kind - b -> kind ;
2946
+ return ( int ) a -> kind - ( int ) b -> kind ;
2947
2947
}
2948
2948
2949
2949
if (a -> kind == ZEND_TYPE_SIMPLE ) {
@@ -2964,15 +2964,15 @@ static int compare_type_nodes(const void *a_, const void *b_) {
2964
2964
return 0 ;
2965
2965
}
2966
2966
2967
- zend_ulong zend_type_node_hash (zend_type_node * node ) {
2967
+ zend_ulong zend_type_node_hash (const zend_type_node * node ) {
2968
2968
zend_ulong hash = 2166136261u ; // FNV-1a offset basis
2969
2969
2970
2970
hash ^= (zend_ulong )node -> kind ;
2971
2971
hash *= 16777619 ;
2972
2972
2973
2973
switch (node -> kind ) {
2974
2974
case ZEND_TYPE_SIMPLE : {
2975
- zend_type type = node -> simple_type ;
2975
+ const zend_type type = node -> simple_type ;
2976
2976
hash ^= (zend_ulong )ZEND_TYPE_FULL_MASK (type );
2977
2977
hash *= 16777619 ;
2978
2978
@@ -2988,7 +2988,7 @@ zend_ulong zend_type_node_hash(zend_type_node *node) {
2988
2988
case ZEND_TYPE_UNION :
2989
2989
case ZEND_TYPE_INTERSECTION : {
2990
2990
for (uint32_t i = 0 ; i < node -> compound .num_types ; ++ i ) {
2991
- zend_ulong child_hash = zend_type_node_hash (node -> compound .types [i ]);
2991
+ const zend_ulong child_hash = zend_type_node_hash (node -> compound .types [i ]);
2992
2992
hash ^= child_hash ;
2993
2993
hash *= 16777619 ;
2994
2994
}
@@ -2999,27 +2999,27 @@ zend_ulong zend_type_node_hash(zend_type_node *node) {
2999
2999
return hash ;
3000
3000
}
3001
3001
3002
- bool zend_type_node_equals (zend_type_node * a , zend_type_node * b ) {
3002
+ bool zend_type_node_equals (const zend_type_node * a , const zend_type_node * b ) {
3003
3003
if (a == b ) return true;
3004
3004
if (a -> kind != b -> kind ) return false;
3005
3005
3006
3006
if (a -> kind == ZEND_TYPE_SIMPLE ) {
3007
- zend_type at = a -> simple_type ;
3008
- zend_type bt = b -> simple_type ;
3007
+ const zend_type at = a -> simple_type ;
3008
+ const zend_type bt = b -> simple_type ;
3009
3009
3010
3010
if (ZEND_TYPE_FULL_MASK (at ) != ZEND_TYPE_FULL_MASK (bt )) {
3011
3011
return false;
3012
3012
}
3013
3013
3014
- bool a_has_name = ZEND_TYPE_HAS_NAME (at );
3015
- bool b_has_name = ZEND_TYPE_HAS_NAME (bt );
3014
+ const bool a_has_name = ZEND_TYPE_HAS_NAME (at );
3015
+ const bool b_has_name = ZEND_TYPE_HAS_NAME (bt );
3016
3016
if (a_has_name != b_has_name ) {
3017
3017
return false;
3018
3018
}
3019
3019
3020
3020
if (a_has_name ) {
3021
- zend_string * a_name = ZEND_TYPE_NAME (at );
3022
- zend_string * b_name = ZEND_TYPE_NAME (bt );
3021
+ const zend_string * a_name = ZEND_TYPE_NAME (at );
3022
+ const zend_string * b_name = ZEND_TYPE_NAME (bt );
3023
3023
if (!zend_string_equals (a_name , b_name )) {
3024
3024
return false;
3025
3025
}
@@ -3042,9 +3042,8 @@ bool zend_type_node_equals(zend_type_node *a, zend_type_node *b) {
3042
3042
return true;
3043
3043
}
3044
3044
3045
-
3046
3045
static zend_type_node * intern_type_node (zend_type_node * node ) {
3047
- zend_ulong hash = zend_type_node_hash (node );
3046
+ const zend_ulong hash = zend_type_node_hash (node );
3048
3047
zend_type_node * existing ;
3049
3048
3050
3049
if (interned_type_tree == NULL ) {
@@ -3054,6 +3053,7 @@ static zend_type_node *intern_type_node(zend_type_node *node) {
3054
3053
3055
3054
if ((existing = zend_hash_index_find_ptr (interned_type_tree , hash ))) {
3056
3055
if (zend_type_node_equals (existing , node )) {
3056
+ pefree (node , 1 );
3057
3057
return existing ; // reuse interned node
3058
3058
}
3059
3059
}
@@ -3062,8 +3062,7 @@ static zend_type_node *intern_type_node(zend_type_node *node) {
3062
3062
return node ;
3063
3063
}
3064
3064
3065
-
3066
- ZEND_API zend_type_node * zend_type_to_interned_tree (zend_type type ) {
3065
+ ZEND_API zend_type_node * zend_type_to_interned_tree (const zend_type type ) {
3067
3066
if (type .type_mask == 0 ) {
3068
3067
return NULL ;
3069
3068
}
@@ -3076,7 +3075,7 @@ ZEND_API zend_type_node *zend_type_to_interned_tree(zend_type type) {
3076
3075
}
3077
3076
3078
3077
zend_type_list * list = ZEND_TYPE_LIST (type );
3079
- zend_type_node_kind kind = ZEND_TYPE_IS_INTERSECTION (type ) ?
3078
+ const zend_type_node_kind kind = ZEND_TYPE_IS_INTERSECTION (type ) ?
3080
3079
ZEND_TYPE_INTERSECTION : ZEND_TYPE_UNION ;
3081
3080
3082
3081
zend_type_node * * children = NULL ;
0 commit comments