File tree 2 files changed +19
-2
lines changed
2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -1512,4 +1512,9 @@ static zend_always_inline bool zend_may_modify_arg_in_place(const zval *arg)
1512
1512
return Z_REFCOUNTED_P (arg ) && !(GC_FLAGS (Z_COUNTED_P (arg )) & (GC_IMMUTABLE | GC_PERSISTENT )) && Z_REFCOUNT_P (arg ) == 1 ;
1513
1513
}
1514
1514
1515
+ static zend_always_inline bool zend_may_modify_string_in_place (const zend_string * arg )
1516
+ {
1517
+ return !(GC_FLAGS (arg ) & (GC_IMMUTABLE | GC_PERSISTENT )) && GC_REFCOUNT (arg ) == 1 ;
1518
+ }
1519
+
1515
1520
#endif /* ZEND_TYPES_H */
Original file line number Diff line number Diff line change @@ -2341,7 +2341,13 @@ static zend_string* php_ucfirst(zend_string *str)
2341
2341
if (r == ch ) {
2342
2342
return zend_string_copy (str );
2343
2343
} else {
2344
- zend_string * s = zend_string_init (ZSTR_VAL (str ), ZSTR_LEN (str ), 0 );
2344
+ zend_string * s ;
2345
+ if (zend_may_modify_string_in_place (str )) {
2346
+ s = str ;
2347
+ zend_string_forget_hash_val (s );
2348
+ } else {
2349
+ s = zend_string_init (ZSTR_VAL (str ), ZSTR_LEN (str ), false);
2350
+ }
2345
2351
ZSTR_VAL (s )[0 ] = r ;
2346
2352
return s ;
2347
2353
}
@@ -2373,7 +2379,13 @@ static zend_string* php_lcfirst(zend_string *str)
2373
2379
if (r == ZSTR_VAL (str )[0 ]) {
2374
2380
return zend_string_copy (str );
2375
2381
} else {
2376
- zend_string * s = zend_string_init (ZSTR_VAL (str ), ZSTR_LEN (str ), 0 );
2382
+ zend_string * s ;
2383
+ if (zend_may_modify_string_in_place (str )) {
2384
+ s = str ;
2385
+ zend_string_forget_hash_val (s );
2386
+ } else {
2387
+ s = zend_string_init (ZSTR_VAL (str ), ZSTR_LEN (str ), false);
2388
+ }
2377
2389
ZSTR_VAL (s )[0 ] = r ;
2378
2390
return s ;
2379
2391
}
You can’t perform that action at this time.
0 commit comments