@@ -270,43 +270,6 @@ PHP_METHOD(Random_Randomizer, getInt)
270
270
}
271
271
/* }}} */
272
272
273
- static zend_always_inline char * bulk_convert_generated_result_to_char_32 (char * ptr , uint64_t result , size_t * to_read )
274
- {
275
- if (* to_read >= sizeof (uint32_t )) {
276
- uint32_t tmp = (uint32_t ) result ;
277
- #ifdef WORDS_BIGENDIAN
278
- tmp = RANDOM_BSWAP32 (tmp );
279
- #endif
280
- memcpy (ptr , & tmp , sizeof (uint32_t ));
281
- ptr += sizeof (uint32_t );
282
- * to_read -= sizeof (uint32_t );
283
- } else {
284
- while (* to_read > 0 ) {
285
- * ptr ++ = result & 0xff ;
286
- result >>= 8 ;
287
- * to_read -= 1 ;
288
- }
289
- }
290
-
291
- return ptr ;
292
- }
293
-
294
- static zend_always_inline char * bulk_convert_generated_result_to_char_64 (char * ptr , uint64_t result , size_t * to_read )
295
- {
296
- if (* to_read >= sizeof (uint64_t )) {
297
- #ifdef WORDS_BIGENDIAN
298
- result = RANDOM_BSWAP64 (result );
299
- #endif
300
- memcpy (ptr , & result , sizeof (uint64_t ));
301
- ptr += sizeof (uint64_t );
302
- * to_read -= sizeof (uint64_t );
303
- } else {
304
- ptr = bulk_convert_generated_result_to_char_32 (ptr , result , to_read );
305
- }
306
-
307
- return ptr ;
308
- }
309
-
310
273
/* {{{ Generate random bytes string in ordered length */
311
274
PHP_METHOD (Random_Randomizer , getBytes )
312
275
{
@@ -336,12 +299,16 @@ PHP_METHOD(Random_Randomizer, getBytes)
336
299
zend_string_free (retval );
337
300
RETURN_THROWS ();
338
301
}
339
- if (EXPECTED (result .size == sizeof (uint64_t ))) {
340
- rptr = bulk_convert_generated_result_to_char_64 (rptr , result .result , & to_read );
341
- } else if (EXPECTED (result .size == sizeof (uint32_t ))){
342
- rptr = bulk_convert_generated_result_to_char_32 (rptr , result .result , & to_read );
302
+
303
+ uint64_t tmp_ret = result .result ;
304
+ if (to_read > result .size && result .size == sizeof (uint64_t )) {
305
+ #ifdef WORDS_BIGENDIAN
306
+ tmp_ret = RANDOM_BSWAP64 (tmp_ret );
307
+ #endif
308
+ memcpy (rptr , & tmp_ret , sizeof (uint64_t ));
309
+ to_read -= sizeof (uint64_t );
310
+ rptr += sizeof (uint64_t );
343
311
} else {
344
- uint64_t tmp_ret = result .result ;
345
312
for (size_t i = 0 ; i < result .size ; i ++ ) {
346
313
* rptr ++ = tmp_ret & 0xff ;
347
314
tmp_ret >>= 8 ;
0 commit comments