1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00

1330 Commits

Author SHA1 Message Date
Weilin Du
da1e89fd3d RFC: Add Form Feed in Trim Functions (#20788)
RFC: https://wiki.php.net/rfc/trim_form_feed

Resolves GH-20783.
2026-03-09 22:28:50 +01:00
Ilija Tovilo
a83c025730 Use zend_always_inline for frameless function template functions (GH-21316) 2026-03-03 00:20:34 +01:00
Alexandre Daubois
1fb4e573ff Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix TypeError message of `setlocale()` (#20625)
2025-12-06 18:06:53 +01:00
Takuya Aramaki
5528df1a20 Fix TypeError message of setlocale() (#20625) 2025-12-06 18:06:19 +01:00
Tim Düsterhus
db8d35e7eb tree-wide: Replace ZEND_WRONG_PARAM_COUNT() by its definition (#20066)
* tree-wide: Replace `WRONG_PARAM_COUNT` by `ZEND_WRONG_PARAM_COUNT()`

This is a direct alias.

* tree-wide: Replace `ZEND_WRONG_PARAM_COUNT()` by its definition

This macro was hiding control flow (the return statement) and thus was
particularly unhygienic.
2025-11-12 21:28:56 +01:00
Niels Dossche
a09cc6ede6 standard: Optimize str_split() (#20419)
Three optimizations:
- If the entire string is returned, we don't need to duplicate it.
- Use packed filling logic.
- Use fast construction of strings. This is useful when splitting
  strings on length=1. In that case I get a 6x speedup in the code
  below.

Bench:
```php
$x = str_repeat('A', 100);
for ($i = 0; $i < 1000000; $i++)
    str_split($x, 10);
```

On an i7-4790:
```
Benchmark 1: ./sapi/cli/php x.php
  Time (mean ± σ):     160.1 ms ±   6.4 ms    [User: 157.3 ms, System: 1.8 ms]
  Range (min … max):   155.6 ms … 184.7 ms    18 runs

Benchmark 2: ./sapi/cli/php_old x.php
  Time (mean ± σ):     202.6 ms ±   4.0 ms    [User: 199.1 ms, System: 1.9 ms]
  Range (min … max):   197.4 ms … 209.2 ms    14 runs

Summary
  ./sapi/cli/php x.php  ran
    1.27 ± 0.06 times faster than ./sapi/cli/php_old x.php
```

The performance gain increases with smaller lengths.
2025-11-08 23:02:00 +01:00
Niels Dossche
9300a5076d Reduce code size of strripos() (#20358)
Reduction of 1325 -> 1213 on x86-64 with GCC 15.2.1.
2025-11-02 15:07:15 +01:00
Niels Dossche
4bd3a9006e Use release_ex consistently in php_strtr_array_ex() (#20359)
Reduces code size from 2056 -> 2006 on x86-64 with GCC 15.2.1.
2025-11-02 15:05:44 +01:00
Alexandre Daubois
80e4278b59 Optimize performances of str_pad() (#19272) 2025-10-03 15:19:03 +02:00
Tim Düsterhus
827c24b33f standard: Use true / false instead of 1 / 0 for bool parameters
Changes done with Coccinelle:

    @r1@
    identifier F;
    identifier p;
    typedef bool;
    parameter list [n1] PL1;
    parameter list [n2] PL2;
    @@

    F(PL1, bool p, PL2) {
    ...
    }

    @r2@
    identifier r1.F;
    expression list [r1.n1] EL1;
    expression list [r1.n2] EL2;
    @@

    F(EL1,
    (
    - 1
    + true
    |
    - 0
    + false
    )
    , EL2)
2025-09-24 18:51:40 +02:00
Tim Düsterhus
c743b71b40 standard: Use return true / return false for functions returning bool
Changes done with Coccinelle:

    @r1@
    identifier fn;
    typedef bool;
    symbol false;
    symbol true;
    @@

    bool fn ( ... )
    {
    <...
    return
    (
    - 0
    + false
    |
    - 1
    + true
    )
    ;
    ...>
    }

Coccinelle patch sourced from
torvalds/linux@46b5c9b856.
2025-09-24 18:51:40 +02:00
Tim Düsterhus
220d7a84b5 standard: Use true / false instead of 1 / 0 when assigning to bool
Changes done with Coccinelle:

    @@
    bool b;
    @@

    - b = 0
    + b = false

    @@
    bool b;
    @@

    - b = 1
    + b = true
2025-09-24 18:51:40 +02:00
Gina Peter Banyard
93676a0425 ext/standard: Deprecate passing string which are not one byte long to ord() (#19440)
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_passing_string_which_are_not_one_byte_long_to_ord

Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
2025-09-14 11:42:59 +01:00
Alexandre Daubois
29c7ee4cd4 Add a 1-char fastpath to implode() (#19276) 2025-09-10 16:52:31 +02:00
Gina Peter Banyard
cab46b27b9 ext/standard: Deprecate passing integers outside the interval [0, 255] to chr() (#19441)
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_passing_integers_outside_the_interval_0_255_to_chr
2025-08-14 20:48:48 +01:00
Niels Dossche
c4183fba00 Fix GH-19070: setlocale($type, NULL) should not be deprecated
This restores the old behaviour.

Closes GH-19071.
2025-07-10 22:01:16 +02:00
DanielEScherzer
4e42ad5bf2 ext/standard/string.c: don't use STR_EMPTY_ALLOC() (#19033)
This was the only remaining use of a compatibility alias from 10 years ago;
replace with `ZSTR_EMPTY_ALLOC()`.
2025-07-04 14:41:24 -07:00
Niels Dossche
43c18f3cfe Fix GH-18823: setlocale's 2nd and 3rd argument ignores strict_types
Closes GH-18828.
2025-06-13 18:24:01 +02:00
Saki Takamachi
47354a7404 Added zend_simd.h (#18413) 2025-05-16 15:42:20 +09:00
Niels Dossche
24fbe2d61e Micro-optimizations to str_increment() and str_decrement() (#18193)
Since it's a new string we're returning we can use RETURN_NEW_STR() and
we can also use zend_string_efree() for the strings that we replace
because they have RC1.
2025-03-30 18:09:21 +02:00
Christoph M. Becker
300811f1e2 Remove support for unsupported MSVC versions (GH-17128)
As of PHP 8.4.0, MSVC >= 1920 (aka. Visual Studio 2019 RTW 16.0) is
required anyway[1], so we can clean up a bit.

[1] <b3d6414b87>
2024-12-12 19:50:14 +01:00
Ilija Tovilo
e122152373 Simplify (bitset & flag) == flag conditions
Closes GH-16558
2024-10-30 17:27:52 +01:00
Gina Peter Bnayard
3f1a4441bd ext/standard: Make char* of php_stristr() const 2024-09-14 14:00:46 +01:00
Gina Peter Banyard
f756b96e06 Make CSV deprecation less annoying to deal with (#15569) 2024-09-13 15:07:26 +01:00
Gina Peter Bnayard
85e6688791 ext/standard/string.c: Remove to(upper|lower) PHP API in favour of Zend APIs 2024-09-12 18:13:01 +01:00
Gina Peter Bnayard
1b87772f40 ext/standard/string.c: Refactor php_spn_common_handler()
Main objective is to remove the PHP_STR_STR(C)SPN symbols which are only used with this static function
2024-09-12 18:13:01 +01:00
Gina Peter Bnayard
5853cdb73d Use "must not" instead of "cannot" wording 2024-08-21 21:12:17 +01:00
Gina Peter Bnayard
997199e938 ext/standard/string.c: use standard wording for ValueError in str_pad() 2024-08-21 21:12:17 +01:00
Gina Peter Bnayard
e7c4d54d65 Use new helper function for "cannot be empty" ValueErrors 2024-08-21 21:12:17 +01:00
Gina Peter Banyard
f5ae5ac804 ext/standard: Throw ValueErrors in str_getcsv() for invalid inputs (#15365)
This was forgotten when adjusting the behaviour of other CSV functions
2024-08-12 17:56:02 +01:00
Gina Peter Banyard
c818d944cf ext/(standard|spl): Deprecate passing a non-empty string as the $enclosure parameter (#15362) 2024-08-12 16:09:56 +01:00
Niels Dossche
5b673e99fc Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix uninitialized (dummy) memory in php_strtr_array() (#14812)
2024-07-04 13:36:46 +02:00
Niels Dossche
6467655568 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix uninitialized (dummy) memory in php_strtr_array() (#14812)
2024-07-04 13:35:53 +02:00
Niels Dossche
7b74cadf8c Fix uninitialized (dummy) memory in php_strtr_array() (#14812)
Fixes one issue in GH-14806.
2024-07-04 13:34:33 +02:00
Niels Dossche
c151d2d135 standard: change uses of sprintf into snprintf and zend_string_concat2 2024-06-14 08:12:03 -07:00
Gina Peter Banyard
25a5146180 Clean-up unused headers (#14365)
* ext/mbstring.c: clean-up headers and include intrinsics
2024-06-01 17:12:42 +01:00
Niels Dossche
75e3f3e0ca Optimize strpbrk (#13558) 2024-03-05 20:51:12 +01:00
Tim Düsterhus
dce6ed3199 random: Adjust status to state (#13521)
* random: Rename `status` local to `state`

* random: Rename `php_random_algo_with_state`'s `status` member to `state`
2024-02-26 20:38:45 +01:00
Tim Düsterhus
79133df156 random: Pass algorithm and state together as php_random_algo_with_state (#13350)
* random: Remove `php_random_status`

Since 162e1dce98, the `php_random_status` struct
contains just a single `void*`, resulting in needless indirection when
accessing the engine state and thus decreasing readability because of the
additional non-meaningful `->state` references / the local helper variables.

There is also a small, but measurable performance benefit:

    <?php
    $e = new Random\Engine\Xoshiro256StarStar(0);
    $r = new Random\Randomizer($e);

    for ($i = 0; $i < 15; $i++)
    	var_dump(strlen($r->getBytes(100000000)));

goes from roughly 3.85s down to 3.60s.

The names of the `status` variables have not yet been touched to keep the diff
small. They will be renamed to the more appropriate `state` in a follow-up
cleanup commit.

* Introduce `php_random_algo_with_state`
2024-02-25 20:48:58 +01:00
Ilija Tovilo
631bc81607 Implement stackless internal function calls
Co-authored-by: Dmitry Stogov <dmitry@zend.com>

Closes GH-12461
2024-02-06 17:42:28 +01:00
Cristian Rodríguez
927adfb1a6 Use a single version of mempcpy(3) (#12257)
While __php_mempcpy is only used by ext/standard/crypt_sha*, the
mempcpy "pattern" is used everywhere.

This commit removes __php_mempcpy, adds zend_mempcpy and transforms
open-coded parts into function calls.
2023-12-20 15:16:32 +00:00
Niels Dossche
e78966386b Remove always-false condition from substr_replace()
l < 0 is checked before and set to a different value.
2023-12-12 16:43:43 +00:00
Vinicius Dias
f1af7223f8 Fixing incorrect error message when passing null to join/implode's array parameter (#12683)
Closes GH-12682
2023-12-01 09:55:20 +00:00
Niels Dossche
9a973a3743 Optimize strcspn (#12594) 2023-11-04 13:54:30 +00:00
Ilija Tovilo
d35faecbf2 Split strtr zpp (#12583) 2023-11-01 13:08:06 +01:00
Niels Dossche
d0b29d8286 Optimize strspn()
The current implementation uses a nested loop (for + goto), which has
complexity O(|s1| * |s2|). If we instead use a lookup table, the
complexity drops to O(|s1| + |s2|).
This is conceptually the same strategy that common C library
implementations such as glibc and musl use.
The variation with a bitvector instead of a table also gives a speed-up,
but the table variation was about 1.34x faster.

On microbenchmarks this easily gave a 5x speedup.

This can bring a 1.4-1.5% performance improvement in the Symfony
benchmark.

Closes GH-12431.
2023-10-14 21:24:55 +02:00
Ilija Tovilo
b31a5b2731 Fix str_decrement() on "1"
Closes GH-12339
2023-10-02 16:42:04 +02:00
Kamil Tekiela
649872f105 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix param name in implode() error message
2023-08-24 21:07:50 +01:00
Kamil Tekiela
ec82927d25 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix param name in implode() error message
2023-08-24 21:07:18 +01:00
Kamil Tekiela
b1ce1d1f21 Fix param name in implode() error message 2023-08-24 21:05:26 +01:00