mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
random: Optimize Randomizer::getBytes() (#15228)
This patch greatly improves the performance for the common case of using a
64-bit engine and requesting a length that is a multiple of 8.
It does so by providing a fast path that will just `memcpy()` (which will be
optimized out) the returned uint64_t directly into the output buffer,
byteswapping it for big endian architectures.
The existing byte-wise copying logic was mostly left alone. It only received an
optimization of the shifting and masking that was previously applied to
`Randomizer::getBytesFromString()` in 1fc2ddc996
.
Co-authored-by: Saki Takamachi <saki@php.net>
This commit is contained in:
parent
2f27e0b2ab
commit
31e2d2b86c
2 changed files with 40 additions and 5 deletions
|
@ -81,8 +81,8 @@ typedef struct _php_random_status_state_user {
|
|||
} php_random_status_state_user;
|
||||
|
||||
typedef struct _php_random_result {
|
||||
const uint64_t result;
|
||||
const size_t size;
|
||||
uint64_t result;
|
||||
size_t size;
|
||||
} php_random_result;
|
||||
|
||||
typedef struct _php_random_algo {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue