@@ -41,15 +41,9 @@ static zend_always_inline bool php_json_check_stack_limit(void)
41
41
#endif
42
42
}
43
43
44
- static int php_json_determine_array_type (zval * val ) /* {{{ */
44
+ static int php_json_determine_array_type (const HashTable * ht ) /* {{{ */
45
45
{
46
- zend_array * myht = Z_ARRVAL_P (val );
47
-
48
- if (myht ) {
49
- return zend_array_is_list (myht ) ? PHP_JSON_OUTPUT_ARRAY : PHP_JSON_OUTPUT_OBJECT ;
50
- }
51
-
52
- return PHP_JSON_OUTPUT_ARRAY ;
46
+ return zend_array_is_list (ht ) ? PHP_JSON_OUTPUT_ARRAY : PHP_JSON_OUTPUT_OBJECT ;
53
47
}
54
48
/* }}} */
55
49
@@ -63,12 +57,10 @@ static inline void php_json_pretty_print_char(smart_str *buf, int options, char
63
57
}
64
58
/* }}} */
65
59
66
- static inline void php_json_pretty_print_indent (smart_str * buf , int options , php_json_encoder * encoder ) /* {{{ */
60
+ static inline void php_json_pretty_print_indent (smart_str * buf , int options , const php_json_encoder * encoder ) /* {{{ */
67
61
{
68
- int i ;
69
-
70
62
if (options & PHP_JSON_PRETTY_PRINT ) {
71
- for (i = 0 ; i < encoder -> depth ; ++ i ) {
63
+ for (int i = 0 ; i < encoder -> depth ; ++ i ) {
72
64
smart_str_appendl (buf , " " , 4 );
73
65
}
74
66
}
@@ -122,7 +114,8 @@ static inline void php_json_encode_double(smart_str *buf, double d, int options)
122
114
123
115
static zend_result php_json_encode_array (smart_str * buf , zval * val , int options , php_json_encoder * encoder ) /* {{{ */
124
116
{
125
- int r , need_comma = 0 ;
117
+ int r ;
118
+ bool need_comma = false;
126
119
HashTable * myht , * prop_ht ;
127
120
zend_refcounted * recursion_rc ;
128
121
@@ -138,17 +131,15 @@ static zend_result php_json_encode_array(smart_str *buf, zval *val, int options,
138
131
myht = Z_ARRVAL_P (val );
139
132
recursion_rc = (zend_refcounted * )myht ;
140
133
prop_ht = NULL ;
141
- r = (options & PHP_JSON_FORCE_OBJECT ) ? PHP_JSON_OUTPUT_OBJECT : php_json_determine_array_type (val );
134
+ r = (options & PHP_JSON_FORCE_OBJECT ) ? PHP_JSON_OUTPUT_OBJECT : php_json_determine_array_type (myht );
142
135
} else if (Z_OBJ_P (val )-> properties == NULL
143
136
&& Z_OBJ_HT_P (val )-> get_properties_for == NULL
144
137
&& Z_OBJ_HT_P (val )-> get_properties == zend_std_get_properties
145
138
&& Z_OBJ_P (val )-> ce -> num_hooked_props == 0
146
139
&& !zend_object_is_lazy (Z_OBJ_P (val ))) {
147
140
/* Optimized version without rebuilding properties HashTable */
148
141
zend_object * obj = Z_OBJ_P (val );
149
- zend_class_entry * ce = obj -> ce ;
150
- zend_property_info * prop_info ;
151
- zval * prop ;
142
+ const zend_class_entry * ce = obj -> ce ;
152
143
153
144
if (GC_IS_RECURSIVE (obj )) {
154
145
encoder -> error_code = PHP_JSON_ERROR_RECURSION ;
@@ -163,15 +154,15 @@ static zend_result php_json_encode_array(smart_str *buf, zval *val, int options,
163
154
++ encoder -> depth ;
164
155
165
156
for (int i = 0 ; i < ce -> default_properties_count ; i ++ ) {
166
- prop_info = ce -> properties_info_table [i ];
157
+ zend_property_info * prop_info = ce -> properties_info_table [i ];
167
158
if (!prop_info ) {
168
159
continue ;
169
160
}
170
161
if (ZSTR_VAL (prop_info -> name )[0 ] == '\0' && ZSTR_LEN (prop_info -> name ) > 0 ) {
171
162
/* Skip protected and private members. */
172
163
continue ;
173
164
}
174
- prop = OBJ_PROP (obj , prop_info -> offset );
165
+ zval * prop = OBJ_PROP (obj , prop_info -> offset );
175
166
if (Z_TYPE_P (prop ) == IS_UNDEF ) {
176
167
continue ;
177
168
}
@@ -270,7 +261,8 @@ static zend_result php_json_encode_array(smart_str *buf, zval *val, int options,
270
261
271
262
php_json_pretty_print_char (buf , options , '\n' );
272
263
php_json_pretty_print_indent (buf , options , encoder );
273
- } else if (r == PHP_JSON_OUTPUT_OBJECT ) {
264
+ } else {
265
+ ZEND_ASSERT (r == PHP_JSON_OUTPUT_OBJECT );
274
266
if (key ) {
275
267
if (ZSTR_VAL (key )[0 ] == '\0' && ZSTR_LEN (key ) > 0 && Z_TYPE_P (val ) == IS_OBJECT ) {
276
268
/* Skip protected and private members. */
@@ -369,7 +361,6 @@ zend_result php_json_escape_string(
369
361
smart_str * buf , const char * s , size_t len ,
370
362
int options , php_json_encoder * encoder ) /* {{{ */
371
363
{
372
- unsigned int us ;
373
364
size_t pos , checkpoint ;
374
365
char * dst ;
375
366
@@ -407,7 +398,7 @@ zend_result php_json_escape_string(
407
398
0xffffffff , 0x500080c4 , 0x10000000 , 0x00000000 ,
408
399
0xffffffff , 0xffffffff , 0xffffffff , 0xffffffff };
409
400
410
- us = (unsigned char )s [pos ];
401
+ unsigned int us = (unsigned char )s [pos ];
411
402
if (EXPECTED (!ZEND_BIT_TEST (charmap , us ))) {
412
403
pos ++ ;
413
404
len -- ;
@@ -626,7 +617,7 @@ static zend_result php_json_encode_serializable_object(smart_str *buf, zend_obje
626
617
627
618
static zend_result php_json_encode_serializable_enum (smart_str * buf , zval * val , int options , php_json_encoder * encoder )
628
619
{
629
- zend_class_entry * ce = Z_OBJCE_P (val );
620
+ const zend_class_entry * ce = Z_OBJCE_P (val );
630
621
if (ce -> enum_backing_type == IS_UNDEF ) {
631
622
encoder -> error_code = PHP_JSON_ERROR_NON_BACKED_ENUM ;
632
623
smart_str_appendc (buf , '0' );
0 commit comments