Skip to content

Commit 50a3cb7

Browse files
authored
Get rid of duplicated rotr3 implementation (#8853)
1 parent 1453dde commit 50a3cb7

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

ext/opcache/zend_shared_alloc.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,17 @@ void *zend_shared_alloc(size_t size)
362362
return NULL;
363363
}
364364

365+
static zend_always_inline zend_ulong zend_rotr3(zend_ulong key)
366+
{
367+
return (key >> 3) | (key << ((sizeof(key) * 8) - 3));
368+
}
369+
365370
int zend_shared_memdup_size(void *source, size_t size)
366371
{
367372
void *old_p;
368373
zend_ulong key = (zend_ulong)source;
369374

370-
key = (key >> 3) | (key << ((sizeof(key) * 8) - 3)); /* key = _rotr(key, 3);*/
375+
key = zend_rotr3(key);
371376
if ((old_p = zend_hash_index_find_ptr(&ZCG(xlat_table), key)) != NULL) {
372377
/* we already duplicated this pointer */
373378
return 0;
@@ -383,7 +388,7 @@ static zend_always_inline void *_zend_shared_memdup(void *source, size_t size, b
383388

384389
if (get_xlat) {
385390
key = (zend_ulong)source;
386-
key = (key >> 3) | (key << ((sizeof(key) * 8) - 3)); /* key = _rotr(key, 3);*/
391+
key = zend_rotr3(key);
387392
if ((old_p = zend_hash_index_find_ptr(&ZCG(xlat_table), key)) != NULL) {
388393
/* we already duplicated this pointer */
389394
return old_p;
@@ -395,7 +400,7 @@ static zend_always_inline void *_zend_shared_memdup(void *source, size_t size, b
395400
if (set_xlat) {
396401
if (!get_xlat) {
397402
key = (zend_ulong)source;
398-
key = (key >> 3) | (key << ((sizeof(key) * 8) - 3)); /* key = _rotr(key, 3);*/
403+
key = zend_rotr3(key);
399404
}
400405
zend_hash_index_add_new_ptr(&ZCG(xlat_table), key, retval);
401406
}
@@ -535,7 +540,7 @@ void zend_shared_alloc_register_xlat_entry(const void *old, const void *new)
535540
{
536541
zend_ulong key = (zend_ulong)old;
537542

538-
key = (key >> 3) | (key << ((sizeof(key) * 8) - 3)); /* key = _rotr(key, 3);*/
543+
key = zend_rotr3(key);
539544
zend_hash_index_add_new_ptr(&ZCG(xlat_table), key, (void*)new);
540545
}
541546

@@ -544,7 +549,7 @@ void *zend_shared_alloc_get_xlat_entry(const void *old)
544549
void *retval;
545550
zend_ulong key = (zend_ulong)old;
546551

547-
key = (key >> 3) | (key << ((sizeof(key) * 8) - 3)); /* key = _rotr(key, 3);*/
552+
key = zend_rotr3(key);
548553
if ((retval = zend_hash_index_find_ptr(&ZCG(xlat_table), key)) == NULL) {
549554
return NULL;
550555
}

0 commit comments

Comments
 (0)