Skip to content

Commit a8dff3d

Browse files
committed
Simplify zend_accel_uintptr_hex
1 parent 28fd87f commit a8dff3d

1 file changed

Lines changed: 9 additions & 17 deletions

File tree

ext/opcache/ZendAccelerator.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,18 +2013,12 @@ static const char hexchars[] = "0123456789abcdef";
20132013

20142014
static char *zend_accel_uintptr_hex(char *dest, uintptr_t n)
20152015
{
2016-
char *start = dest;
2017-
dest += sizeof(uintptr_t)*2;
2018-
2019-
while (n > 0) {
2020-
*--dest = hexchars[n % strlen(hexchars)];
2021-
n /= strlen(hexchars);
2022-
}
2023-
while (dest > start) {
2024-
*--dest = '0';
2025-
}
2016+
do {
2017+
*dest++ = hexchars[n & 0xf];
2018+
n >>= 4;
2019+
} while (n);
20262020

2027-
return dest + sizeof(uintptr_t)*2;
2021+
return dest;
20282022
}
20292023

20302024
/* Prevents collisions with real scripts, as we don't cache paths prefixed with
@@ -2034,8 +2028,8 @@ static char *zend_accel_uintptr_hex(char *dest, uintptr_t n)
20342028
static zend_string *zend_accel_pfa_key(const zend_op *declaring_opline,
20352029
const zend_function *called_function)
20362030
{
2037-
const size_t key_len = strlen(PFA_KEY_PREFIX) + (sizeof(uintptr_t)*2) + strlen(":") + (sizeof(uintptr_t)*2);
2038-
zend_string *key = zend_string_alloc(key_len, 0);
2031+
const size_t max_key_len = strlen(PFA_KEY_PREFIX) + (sizeof(uintptr_t)*2) + strlen(":") + (sizeof(uintptr_t)*2);
2032+
zend_string *key = zend_string_alloc(max_key_len, 0);
20392033
char *dest = ZSTR_VAL(key);
20402034

20412035
dest = zend_mempcpy(ZSTR_VAL(key), PFA_KEY_PREFIX, strlen(PFA_KEY_PREFIX));
@@ -2055,10 +2049,8 @@ static zend_string *zend_accel_pfa_key(const zend_op *declaring_opline,
20552049
}
20562050
dest = zend_accel_uintptr_hex(dest, (uintptr_t)ptr);
20572051

2058-
ZEND_ASSERT(dest == ZSTR_VAL(key) + key_len);
2059-
2060-
ZSTR_VAL(key)[key_len] = 0;
2061-
ZSTR_LEN(key) = key_len;
2052+
*dest = '\0';
2053+
ZSTR_LEN(key) = dest - ZSTR_VAL(key);
20622054

20632055
return key;
20642056
}

0 commit comments

Comments
 (0)